Iphone 已调用通知,但标签不会更新
我使用Iphone 已调用通知,但标签不会更新,iphone,ios,xcode,ios5,Iphone,Ios,Xcode,Ios5,我使用NSNotificationcenter调用了以下代码,我知道它被调用了,因为数组出现在NSLog中,但我的标签chipCount没有用新值更新。从数组中提取字符串时,是否存在我应用错误的方法 -(NSString *) dataFilePath { NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docume
NSNotification
center调用了以下代码,我知道它被调用了,因为数组出现在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];
}
}
假设chipcount是一个UILabel。。您是否需要告诉它刷新标签
[chipcount setNeedsDisplay];
只是一个想法。我认为这是一个多线程问题。必须在主线程中更新UI。可能
readPlist
是在另一个线程中执行 请尝试下面的代码,也许它可以帮助您:
[self performSelectorOnMainThread:@selector(theProcess:) withObject:nil waitUntilDone:YES];
- (void) theProcess:(id)sender
{
....
chipCount.text = [NSString stringWithFormat:@"%i", chipsFloat];
}
是的,它在我的标题中是iblabel*chipCount;如果您在标签中没有看到任何内容,我建议您尝试将其设置为常量字符串值(如果尚未设置)。这至少可以排除你的标签连接不正确的可能性。确保你在主线程中!用户界面只能在此处更改。有关详细信息,请参见此。请尝试在此方法结尾处
NSLog(@“loaded:%@,转换为:%i”、chipcountString、chipsFloat)
,并查看它是否符合您的预期。如果连接正确,则它是一个从父视图获取芯片计数的子视图,但是,子视图会打开另一个视图,该视图编辑该值,并尝试使用新值重置视图中的值