2012-06-21 32 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]; 

只是一個想法。