0

外部クラス ( ) クラスで JSON データをNSObject解析すると、解析されたデータが配列に整理されます。その配列は、テーブル ビューに配置されます。情報の解析に時間がかかるためviewDidLoad、配列は常に nil に設定されます。

コード:

- (void)viewDidLoad
{
//Fetching Data
[super viewDidLoad];
myClass = [[MyClass alloc] init];
[myClass fetchDataWithTarget:self];

//Initialize the dataArray
dataArray = [[NSMutableArray alloc] init];

//First section data
NSArray *firstItemsArray = myClass.fechedDataArray;
NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:firstItemsArray forKey:@"data"];
[dataArray addObject:firstItemsArrayDict];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

NSDictionary *dictionary = [dataArray objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"data"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

return cell;
}  

firstItemsArrayデータがフェッチされた後に設定されていることを確認するにはどうすればよいですか。

注:テーブルビューには明らかにこれ以上のものがあります。セクションを分離するためにすべての辞書を作成しました。

4

1 に答える 1

0

JSONデータを配列にロードする前に

- (void) viewDidLoad

または、次のようなタイプのスレッド (非同期メソッド) を使用します。

performSelectorInBackground:withObject

NSOperation または Grand Central Dispatch

于 2013-06-11T03:25:15.993 に答える