0

次のコードが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];
    }
}
4

2 に答える 2

1

これはマルチスレッドの問題だと思います。メイン スレッドで UI を更新する必要があります。別のスレッドreadPlist
実行されている可能性があります。

以下のコードを試してみてください。

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

- (void) theProcess:(id)sender
{

    ....

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

}
于 2012-09-19T07:29:31.517 に答える
0

chipcount が UILabel であると仮定すると、ラベルを更新するように指示する必要がある可能性はありますか?

[chipcount setNeedsDisplay];

ただのアイデア。

于 2012-06-21T20:24:07.830 に答える