Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 将数组键用作UITableView行的标签_Objective C_Arrays_Cocoa Touch_Uitableview - Fatal编程技术网

Objective c 将数组键用作UITableView行的标签

Objective c 将数组键用作UITableView行的标签,objective-c,arrays,cocoa-touch,uitableview,Objective C,Arrays,Cocoa Touch,Uitableview,我试图使用plist中数组中的键作为表的标签。这就是我到目前为止所尝试的。 我已经声明了一个ivar:NSArray*viewerKeys 在viewDidLoad中 `NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); // get documents path NSString *documentsPath = [paths objectAtInd

我试图使用plist中数组中的键作为表的标签。这就是我到目前为止所尝试的。 我已经声明了一个ivar:
NSArray*viewerKeys

在viewDidLoad中

`NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:(NSString *)plistPath];
viewerKeys = [dictionary allKeys];`
在cellForRowAtIndexPath中
UILabel*label=(UILabel*)[带标签的单元格视图:1000];
label.text=[viewerKeys objectAtIndex:indexPath.row]


我可以从viewdidload中记录viewerKeys,但是如果我尝试
NSLog@“%@,[viewerKeys objectATIndex:indexPath.row]
我什么都没有得到,甚至不是空的。

我没有正确计算节中的行数。我错了

你能从
viewdiload
cellforrowatinexpath:
复制并粘贴你正在使用的确切代码吗?为什么不登录
[dictionary allkey]有可能是空白的,这就是确切的代码-正如我所说,当我记录viewerKeys时会得到一个结果(这等于
[dictionary allKeys]
)。虽然我没有在CellForRowatineXpath中使用viewerKeys尝试过,但是如果
viewerKeys
被定义为属性,那么只需分配
self.viewerKeys=[dictionary allKeys]。或
[viewerKeys retain]不确定。请试一试。我已添加了属性
@property(非原子,保留)NSArray*viewerKeys
,并将所有对
viewerKeys
的引用更改为
self.viewerKeys
。不走运。