在成功地( :D)与我的服务器通信之后,我绑定到解析它返回我的一个xml文件。根据我正在打印的内容,我假设解析工作进行得相当顺利。问题是,我是新来的,对NSXMLParser非常陌生,不能在模拟器上的设备屏幕上的小行部分全部打印出来。我显示行,但它们是空的,其中没有显示任何内容。如果一个习惯了NSXMLParser或其他东西的人可以给我建议或者告诉我如果它变得凌乱的话,请:
- (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]];
}发布于 2013-11-05 16:21:34
如果您确信您的xml响应已被很好地解析(而且[stories count]返回18行的事实似乎至少是正确的).
在你的-cellFOrRowAtIndexPath中试试这个
...
// 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;
}当断点激活时,检查您在strSizing中得到了什么,或者只是检查整个stories对象以获得更好的想法。
我的xcode现在不在我身边,所以请接受我和我的简单建议
https://stackoverflow.com/questions/19792804
复制相似问题