私のヘッダーファイルには次のものがあります:
@property (nonatomic, retain) NSMutableArray * array1;
そして私のinitWithNibName
方法では:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.array1 = [[NSMutableArray alloc] initWithObjects:@"test", nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DoUpdateLabel:) name:@"DoUpdateLabel" object:nil];
}
return self;
}
このDoUpdateLable
メソッドは、配列を更新します (いくつかの項目を追加します)。これが完了してViewDidLoadが実行されると、配列が消えてnullになり、テーブルビューにロードしたいので面倒です。
DoUpdateLable
メソッドの縮小版を次に示します。実際のメソッドには多くの JSON 解析と URL 要求が含まれているため、それを削減する必要がありました。
-(void)DoUpdateLabel:(NSNotification *) notification
{
int count = 0;
while(count < 59)
{
NSString * currentpatname = @"test1";
if(![currentpatname isEqualToString:@""])
{
[self.array1 addObject:currentpatname];
NSLog(@"array: %@", self.array1);
}
count++;
}
NSLog(@"final array: %@", self.array1);
}
保持されていない理由について、私は少し立ち往生しています。どんな助けでも大歓迎です!
ありがとう!