首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSXMLParser NSString

NSXMLParser NSString
EN

Stack Overflow用户
提问于 2013-11-05 15:39:33
回答 1查看 126关注 0票数 1

在成功地( :D)与我的服务器通信之后,我绑定到解析它返回我的一个xml文件。根据我正在打印的内容,我假设解析工作进行得相当顺利。问题是,我是新来的,对NSXMLParser非常陌生,不能在模拟器上的设备屏幕上的小行部分全部打印出来。我显示行,但它们是空的,其中没有显示任何内容。如果一个习惯了NSXMLParser或其他东西的人可以给我建议或者告诉我如果它变得凌乱的话,请:

代码语言:javascript
复制
- (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]];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-05 16:21:34

如果您确信您的xml响应已被很好地解析(而且[stories count]返回18行的事实似乎至少是正确的).

在你的-cellFOrRowAtIndexPath中试试这个

代码语言:javascript
复制
...
// 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现在不在我身边,所以请接受我和我的简单建议

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19792804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档