1

After successfully ( :D) communicating with my server, i'am tying to parse a xml file that it returns me. According to what i'am printing i assume that the parsing is going rather well. The problem is that i'am new, very very very new to NSXMLParser, and don't manage to print it all in little row sections in my device screen on the simulator. i display the rows but they are empty, nothing is displayed in them. if someone who is used to NSXMLParser or anything else could give me advice or show me were it gets messy please:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [stories count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath {

    static NSString *MyIdentifier = @"MyIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}

// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
[cell setText:[[stories objectAtIndex: storyIndex] objectForKey: @"sizing"]];

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic

    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

    NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"module"];

    storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"  " withString:@""];

    NSLog(@"link: %@", storyLink);
     //open in safari
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
}
Hakeem El Bakka-lee
  • 756
  • 1
  • 7
  • 23
  • When you say "put[ting] everything on the screen doesn't work," in what way does it not work? Does it not display everything? Does it display, but in the wrong order? Is the formatting wrong? We need more detail about what's going wrong. – user1118321 Nov 05 '13 at 15:45
  • Sorry i didn't formulate my question well, it doesn't display anything on the screen except the 18 rows needed, but they are empty(i will re-edit my question). – Hakeem El Bakka-lee Nov 05 '13 at 15:59
  • Generally, you should post new questions rather than adding to the existing one if it's a different topic (such as optimization rather than more problems with the same section of code). – user1118321 Nov 05 '13 at 17:03

1 Answers1

1

if you're confident that your xml response has been parsed well (and the fact that [stories count] returns 18 rows seems atleast something is working correctly)...

try this in your -cellFOrRowAtIndexPath instead

...
// Set up the cell
NSString *strSizing = [[stories objectAtIndex:indexPath.row]
                                 objectForKey:@"sizing"];
[cell setText:strSizing];
//optional: uncomment the following line
//stories;
//enable breakpoint on this line
return cell;
}

when breakpoint activates, check what you get in strSizing or simply just check the entire stories object to get a better idea.


i don't have my xcode near me right now so bear with me and my simple suggestion

staticVoidMan
  • 19,275
  • 6
  • 69
  • 98
  • That suggestion was awesome worked right away :D !!! The Breakpoint show were it gets messed up, my index was wrong Thank you very much !! – Hakeem El Bakka-lee Nov 05 '13 at 16:32
  • great :) in such cases i simply do this... (check the edited answer). anyways, yes, your int variable did look messed up (but i wasn't sure) – staticVoidMan Nov 05 '13 at 16:35
  • Thank you for the advice, :3 i'am new to objective c. Maybe can i ask a improvement question to push this further ? – Hakeem El Bakka-lee Nov 05 '13 at 17:00
  • you may, i guess, as long as it doesn't change the context of the original question... in which case it better be posted as a new question (rather than editing this one). refer: http://stackoverflow.com/help/dont-ask to be in the good-question safe zone. :) – staticVoidMan Nov 05 '13 at 17:17