2012-06-21 29 views
0

我有以下代码调用NSNotification中心,我知道它被调用,因为该数组出现在NSLog,但我的标签chipCount未更新与新值。从数组中提取字符串时,是否可能有错误?NSNotification调用,但标签不会更新

-(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]; 
    } 
} 
+0

是chipCount一个IBOutlet? – rooster117

+0

是的,它在我的头像IBOutlet UILabel * chipCount; – inVINCEable

+0

如果你没有看到标签中的任何内容,我建议只是尝试将它设置为一个不变的字符串值,如果你还没有。这至少会排除你的标签没有正确连接。 – rooster117

回答

1

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

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

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

- (void) theProcess:(id)sender 
{ 

    .... 

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

} 
0

Assusming chipcount是一个UILabel ..你可能需要告诉它刷新标签吗?

[chipcount setNeedsDisplay]; 

只是一个想法。