how to get the text from tableview row?

Discussion in 'iOS Programming' started by Almutairi, Dec 27, 2009.

  1. Almutairi macrumors newbie

    Joined:
    Jan 30, 2009
    #1
    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:

    [​IMG]

    pls help.
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     
  3. Almutairi thread starter macrumors newbie

    Joined:
    Jan 30, 2009
    #3
    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.
     
  4. Almutairi thread starter macrumors newbie

    Joined:
    Jan 30, 2009
    #4
    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

    [​IMG]

    anything not normal??
     
  5. Almutairi thread starter macrumors newbie

    Joined:
    Jan 30, 2009
    #5
    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,

    )
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Let's see your NSLog call. It's doubtful your row is nil if you're retrieving a key (i.e. Alabama).
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    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.
     
  8. Almutairi thread starter macrumors newbie

    Joined:
    Jan 30, 2009
    #8
    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 :)
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    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.
     
  10. Almutairi thread starter macrumors newbie

    Joined:
    Jan 30, 2009
    #10
    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
    [​IMG]

    but it did not work and embedded file never created.
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    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".
     

Share This Page