سؤال

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]];
}
هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top