gpt4 book ai didi

iphone - NSNotification 被调用,但标签不会更新

转载 作者:行者123 更新时间:2023-11-29 04:35:17 25 4
gpt4 key购买 nike

我使用 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];
}
}

最佳答案

我认为这是一个多线程问题。更新UI必须在主线程中。也许 readPlist
在另一个线程中执行。

试试下面的代码,也许它可以帮助你:

[self performSelectorOnMainThread:@selector(theProcess:) withObject:nil waitUntilDone:YES]; 

- (void) theProcess:(id)sender
{

....

chipCount.text = [NSString stringWithFormat:@"%i", chipsFloat];

}

关于iphone - NSNotification 被调用,但标签不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11142701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com