Xcode を使用して iOS アプリを作成しています。SQL サーバー (xampp) も使用しています。それは全体的にうまく機能します。しかし、次の点で問題があります。
-Table View を備えた View Controller があり、SQL クエリの結果を使用してこのテーブルにデータを入力しています (taglist が 12 行を含む配列であると想像してください)
- (void)viewDidLoad
[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"listtags", @"command", nil] onCompletion:^(NSDictionary *json) {
NSArray* result = [[NSArray alloc] initWithArray:[json objectForKey:@"result"]];
taglist =[[NSMutableArray alloc] initWithArray:result];
[taglist removeAllObjects];
for(NSDictionary* i in result){
[taglist addObject:[i objectForKey:@"tag"]];
}
NSLog(@"sql %u",taglist.count);
}];
NSLog(@"did load %u",taglist.count);
}
また、テーブルビューには2つの必須メソッドがあります
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(@"table %u",taglist.count);
return taglist.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSLog(@"cell %u",taglist.count);
cell.textLabel.text = [taglist objectAtIndex:indexPath.row];
return cell;
}
問題は、クエリ結果を取得するのに時間がかかるため、テーブル メソッドが空のタグリスト配列を使用してデータを入力することです。NSLogs の出力は次のようになります。
2012-12-19 14:35:41.470 iReporter[33507:c07] did load 0
2012-12-19 14:35:41.473 iReporter[33507:c07] table 0
2012-12-19 14:35:41.476 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.479 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.481 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.483 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.484 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.486 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.487 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.489 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.493 iReporter[33507:c07] cell 0
2012-12-19 14:35:41.564 iReporter[33507:c07] sql 12
これは、 viewDidload 、 numberofRows 、および cellForRow 関数の後、タグリスト配列が空であることを意味します。しかし、クエリが完了すると、正しい値を取得できます。しかし、それまでに私のテーブルのプロパティはすでに定義されているので、それは役に立たない. ありがとうございました