Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2012, 11:59 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 6
narutov2 is on a distinguished road
Default Help with Table views and Alert Views

hi I am new so I hope I am posting in the right section, I am a bit confused in what I am doing here, as I started learning about iphone sdk recently. I am working on a table view application where I want a different alert message given per item in my array. I am working base on one of the examples in http://www.amazon.com/Beginning-iPho.../dp/1430216263


I am using an array to store information for each cell in my table view application :
NSArray *array = [[NSArray alloc] initWithObjects:@"Academic Department", @"Administration",
@"Ball Room", @"Bearcat Louge", @"Board Room", @"Book Store", @"Cafeteria", @"Carey Louge",
@"Cis Computer Lab",@"Commuter Lounge", @"Financial Aid", @"Foundation Room", nil];


and I am trying to give an different alert string for each one: here is what I have so far:


NSUInteger row = [indexPath row];
NSString *rowValue =[listData objectAtIndex:row];

NSString *message = [[NSString alloc] initWithFormat:@"You selected %@",rowValue];
UIAlertView *alert = [[UIAlertView alloc]
// if("%@" =="Commuter Lounge")
initWithTitle:message message: alertmessage delegate:nil cancelButtonTitle:@"Go Back" otherButtonTitles:nil];



I was planning to use a string variable to store the actual message, which is the underlined part, but I am running into problems in comparing a array string to to a match, because I was planning to make a if comparison to each element in my array.

I was trying things like

if %@ == commuter lounge
then alertmessage= "commuter lounge is a place where commuters could stay for breaks"


But it isn't recognizing it. I am really not familiar with the language yet, so please feel free to suggest
narutov2 is offline   Reply With Quote
Old 02-05-2012, 01:03 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

"==" compares memory addresses. To compare the actual string, you need to use isEqualToString:. So:
Code:
if ([aString isEqualToString:anotherString]) {
}
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 02-08-2012, 01:19 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 6
narutov2 is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
"==" compares memory addresses. To compare the actual string, you need to use isEqualToString:. So:
Code:
if ([aString isEqualToString:anotherString]) {
}
thanks for the syntax hint, but I am getting warning and would crash with a error.

This is what I have

NSString *message = [[NSString alloc] initWithFormat:
@"You selected %@",rowValue];

if (["%@" isEqualToString:"Commuter Lounge"]) {
alertMessage = @"the string";
}

the warnings are "invalid receiver type char[3]" and "passing argument 1 of isequaltostring incompatible pointer type" which I think is because I am using %@ to compare and it isn't getting it

But the error I get when it crashes is "thread 1 program received signal ex bad access"

The reason I am using %@ in this program was that when you select a cell in the table view it will let say "you selected %@" and that %@ is replaced by something from the array I think. Is there a way I can compare the value selected from table view at all? Or is my approach wrong? or is there a different way to represent the value in the string compare?
narutov2 is offline   Reply With Quote
Old 02-08-2012, 01:26 AM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Instead of %@ use message. %@ is a format specifier.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 405
18 members and 387 guests
Apptronics RBC, Atatator, chiataytuday, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, kukat, LunarMoon, MAMN84, n00b, pbart, reficul, Retouchable, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:14 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0