objective-c - NSXMLParser NSString

标签 objective-c xml cocoa nsxmlparser nsxml

与我的服务器成功通信后(: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]];
}

最佳答案

如果您确信您的 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,所以请耐心等待我和我的简单建议

关于objective-c - NSXMLParser NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19792804/

相关文章:

objective-c - 移动特定对象后获取贝塞尔曲线的点

ios - 通过替换 Windows 根 Controller 在多个 Storyboard之间移动

iphone - 尝试从 iphone 连接到 node.js 和 socket.io 0.7.2

java - XML 映射到 Java 对象的库,而不必在编译时从 xsd 生成源代码?

objective-c - 如何在 Cocoa 中获取当前日期

objective-c - 部分隐藏的 NSView 上的鼠标进入/退出事件

iphone - UIPickerview 多个文本字段 Xcode

c# - Linq to Object/XML 其中元素不存在

macos - Mac 应用程序崩溃时,CrashReporter 对话框不显示

xml - 用于 @ConfigurationProperties 的自定义基于 XML 的属性源加载器