【发布时间】:2012-06-21 16:35:19
【问题描述】:
我用NSNotification 中心调用了以下代码,我知道它被调用是因为数组出现在NSLog 中,但我的标签chipCount 没有用新值更新。从数组中提取字符串时,我是否应用了错误的方法?
-(NSString *) dataFilePath {
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:@"Chips.plist"];
}
-(void)readPlist {
[self dataFilePath];
NSString *filePath = [self dataFilePath];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
chipArray = [[NSArray alloc] initWithContentsOfFile:filePath];
NSLog(@"%@\n", chipArray);
NSLog(@"%@\n", filePath);
NSString *chipcountString = [chipArray objectAtIndex:0];
chipsFloat = [chipcountString intValue];
chipCount.text = [NSString stringWithFormat:@"%i", chipsFloat];
//[arrayForPlist release];
}
}
【问题讨论】:
-
是的,它在我的标题中是 IBOutlet UILabel *chipCount;
-
如果您在标签中没有看到任何内容,我建议您尝试将其设置为常量字符串值(如果您还没有的话)。这至少可以排除您的标签未正确连接。
-
确保你在主线程中!用户界面只能在那里更改。请参阅此link 了解更多信息。
-
在这个方法的最后尝试
NSLog(@"loaded: %@, converted to: %i", chipcountString, chipsFloat),看看是否是你所期望的。 -
它连接正确,它是一个子视图,它最初从父视图获取芯片计数,但随后子视图打开另一个视图,该视图编辑值并尝试重置视图中的值使用新值