Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Almutairi

macrumors newbie
Original poster
Jan 30, 2009
10
0
hi,

i am new to iphone programming and working now on a simple app.

i have a plist which has multiple array and each array with multiple items (numbers). loaded and connected perfectly to the tableview.

the problem is whenever i click in a row to get the AlertView msg to show only the selected row it loads all the rows at once with parentheses at the beginning and at the end of the list . (look at the pic).

this is the code used to load from the plist.

Code:
-(void) viewDidLoad {
	NSString *path = [[NSBundle mainBundle] pathForResource:@"hilton" ofType:@"plist"];
	NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
	self.names = dict;
	[dict release];
	NSArray *arrray	 = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
	self.keys = arrray;
}

here is the alertview code:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
	
		NSUInteger row = [indexPath row];
		NSString *key = [keys objectAtIndex: row];
		NSString *rowValue = [names objectForKey:key];

		NSString *addresss = [[NSString alloc] initWithFormat:@"%@", key];
		NSString *title = [[NSString alloc] initWithFormat:@"%@", rowValue];
		
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:addresss message:title delegate:nil cancelButtonTitle:@"yes" otherButtonTitles:nil];
		[alert show];
		[alert release];
		[title release];	
}




i think the problem is in this piece of code but i don't know what>
Code:
		NSUInteger row = [indexPath row];
		NSString *key = [keys objectAtIndex: row];
		NSString *rowValue = [names objectForKey:key];


this is what happen when i click the row:

hs7tlf.png


pls help.
 
Maybe the problem is in the contents of the plist file. How do you create it? What happens if you print out the dictionary when the plist is loaded?

Your code appears to be correct.
 
How do you create it?

even if i used any other plist made by some one else, i get the same result ... it must be something wrong with the code it self.
:confused:

thank you.
 
Code:
here is the plist opened by TextEditor

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Adam</key>
	<array>
		<string>98787873</string>
	</array>
	<key>John</key>
	<array>
		<string>22223335555</string>
	</array>
</dict>
</plist>

and the pic

wjpm0.png


anything not normal??
 
after checking with NSlog it turns to be that row = (null) !!!
and the rowValue loads all items in section !!!

mercy pls !!:confused:

2009-12-28 13:59:41.256 Retaurants[13312:20b] row=(null), key=Alabama, rowValue = (
35004,
35005,
35006,
35007,
35010,
35014,

)
 
Your code doesn't match the structure of the plist. The plist has a dictionary with keys and values. The keys are strings and the values are arrays. Your code expects keys as strings and values as strings.

Since I don't know what the app is trying to accomplish I don't know which is wrong, the plist structure or the code.
 
it finally works !:)

this is the new code

Code:
	NSUInteger section = [indexPath section];
	NSUInteger row = [indexPath row];
	NSString *key = [keys objectAtIndex:section];
	NSArray *nameSection = [names objectForKey:key];
	NSString *numberos = [nameSection objectAtIndex:row];

don't ask me what is what and where is where !! am still confused ... but it works now ;)

thank you so much for helping me !

PhoneyDeveloper your a life saver :)
 
don't ask me what is what and where is where !! am still confused ... but it works now ;)
I'm gonna say that normally it is not a good idea to just move on from code that you've written but don't understand how it works. What you've shown us is not that complicated; it would behoove you to learn and understand exactly what it is doing.
 
I'm gonna say that normally it is not a good idea to just move on from code that you've written but don't understand how it works. What you've shown us is not that complicated; it would behoove you to learn and understand exactly what it is doing.

dejo ur absolutely right, i agree with you. it was confusing at the beginning but now am fine with it. thanks for the valuable advice.

i have another question though. when i try to Build my app for distribution it never creates the embedded.mobileprovision file. i think the problem is in the identifier. i am for sure missing something there.

my App ID is something like A1B2C3D4E5.* but i am not sure how to change the identifier accordingly. so i tried this
23w1ph5.png


but it did not work and embedded file never created.
 
i have another question though. when i try to Build my app for distribution it never creates the embedded.mobileprovision file. i think the problem is in the identifier. i am for sure missing something there.

my App ID is something like A1B2C3D4E5.* but i am not sure how to change the identifier accordingly. so i tried this
23w1ph5.png


but it did not work and embedded file never created.
Make sure you are following the instructions from the Program Portal as closely as possible, in particular you'll want to pay attention to Step 6 of the "Building your Application with Xcode for Distribution" section in Distribution > Prepare App tab. Your identifier seems to match with the App ID and not the "Identifier to enter in Xcode".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.