2012-06-27 91 views
0

我有一个plist上传到服务器上。当我登录的阵列:用远程Plist填充UITableView

NSLog(@"My Array: %@", topModsArray); 

它显示:

"New item 0", 
    { 
    curVersion = "1.2.5"; 
    description = "This mod enables you to install other mods, does not modify the gameplay itself, helps other mods to."; 
    maker = Risugami; 
    mcVersion = "1.2.5"; 
    name = ModLoader; 
    rating = 5; 
    requires = Nothing; 
}, 
"New item 1", 
    { 
    curVersion = "3.3.8.153"; 
    description = "This mod is like ModLoader, it allows other mods to be installed and work properly. This adds more capability for developers when making their mods."; 
    maker = SpaceToad; 
    mcVersion = "1.2.5"; 
    name = "Minecraft Forge"; 
    rating = 5; 
    requires = ModLoader; 
}, 
"New item 2", 
    { 
    curVersion = "1.2.5"; 
    description = "This mod gives capability for clients to use certain mods and for servers to be modded."; 
    maker = Flan; 
    mcVersion = "1.2.5"; 
    name = ModLoaderMP; 
    rating = 5; 
    requires = ModLoader; 
}, 
"New item 3", 
    { 
    curVersion = "3.6.2"; 
    description = "This mod adds much more mobs to minecraft, making the game more fun and enjoyable. (Be warned it adds much more hostile mobs, and in the water)"; 
    maker = DrZhark; 
    mcVersion = "1.2.5"; 
    name = "Mo' Creatures"; 
    rating = 5; 
    requires = "ModLoader, Minecraft Forge, GUI API and CustomMobSpawner"; 
}, 
"New item 4", 
    { 
    curVersion = "3.1.5"; 
    description = "This mod makes minecraft more realistic with pipes, quarrys, machines, and much more. If you want your minecraft to be more realistic, this is a must have mod."; 
    maker = "SirSengir (Now Opensource)"; 
    mcVersion = "1.2.5"; 
    name = Buildcraft; 
    rating = 5; 
    requires = "ModLoader and Minecraft Forge"; 
} 

这是我希望它显示什么,但是当我尝试名称键与它添加到一个UITableView:

cell.textLabel.text = [[topModsArray objectAtIndex:indexPath.row] objectForKey:@"name"]; 

我的应用程序崩溃与SIGABRT:

2012-06-27 12:54:37.765 MinePedia[72019:f803] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x6c8bad0 
2012-06-27 12:54:37.766 MinePedia[72019:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x6c8bad0' 
*** First throw call stack: 
(0x13bd052 0x154ed0a 0x13beced 0x1323f00 0x1323ce2 0x3424 0xade0f 0xae589 0x99dfd 0xa8851 0x53301 0x13bee72 0x1d6792d 0x1d71827 0x1cf7fa7 0x1cf9ea6 0x1d8530c 0x25530 0x13919ce 0x1328670 0x12f44f6 0x12f3db4 0x12f3ccb 0x12a6879 0x12a693e 0x14a9b 0x2868 0x27c5) 
terminate called throwing an exceptionsharedlibrary apply-load-rules all 
Current language: auto; currently objective-c 
(gdb) 

请帮我

+0

异常意味着你的[[topModsArray objectAtIndex:indexPath.row]是一个的NSString,而不是字典 – janusbalatbat

+0

尝试记录一些信息,以清除信息 - NSLog(@“%@”,[topModsArray objectAtIndex:0]); NSLog(@“%@”,[[topModsArray objectAtIndex:0] objectForKey:@“New item 0”]); – rishi

+0

NSLog(@“%d”,[topModsArray objectAtIndex:0] .count);这是回报2 ..? – Shorhashi

回答

1

看到使其鉴于没有负载在.H或Alloc一个数组,并用它来显示你的表格,让你的阵列是这样的...

for(int i =0 ;i <topModsArray.count ; i++){ 
    id object = [topModsArray objectAtIndex:i]; 
if([object isKindOfClass:[NSMutableDictionary class]] || [object isKindOfClass:[NSDictionary class]]){ 
    NSMutableDictionary *dict = (NSMutableDictionary *)object; 
    [yourArray addObject:dict]; 
} 

现在返回的行数是yourArray .Count之间,在你的cellForRowAtIndexPath:

NSMutableDictionary *dict = [yourArray objectAtIndexPath:indexPath.row]; 
cell.titleLabel.text = [dict objectForKey:@"name"]; 

使用这可能这个帮助你

+0

可能会做,但我的'topModsArray'是一个NSMutableArray – 21zach2

+0

没问题,你只是这样做,它可以解决你的问题 – Abhishek

+0

正确的这种作品,它显示名称键,但每隔一个细胞。没有任何内容的单元会崩溃应用程序,但另一个会推动下一个视图:)。我如何删除没有任何东西的单元格 – 21zach2

0

你的数组是由交替的字符串和字典组成。零点偏移处的对象是“New item 0”,它没有objectForKey:方法。您需要从阵列中选择您实际想要显示的项目(...或使用类似indexPath.row * 2 + 1的索引)。

+0

但我正在用我的plist来更换标签和其他东西。我将如何能够从plist数组内的字典中获得“名称”键? 我只想在表格视图中的“名称”键中显示值 – 21zach2

+0

就像我说的那样,将字典移动到他们自己的数组中或计算右偏移量。未检测,但可能是:'cell.textLabel.text = [[topModsArray objectAtIndex:indexPath.row * 2 + 1] objectForKey:@“name”];' –

+0

什么这么改''到''的XML plist?然后做另一点? – 21zach2