Webサービスからデータを取得する前にテーブルがロードされている状況があります。connectionDidFinishLoadingからデータを取得する前にUITableViewが表示される
デバッグすると、NSMutableArray
に123個のオブジェクトがありますが、テーブルに反映されていないことがわかります。
これは私のconnectionDidFinishLoading
方法です:
-(void)connectionDidFinishLoading:(NSURLConnection *)conn{
myData = [[NSString alloc] initWithData:xData encoding:NSUTF8StringEncoding];
SBJsonParser *jParser = [SBJsonParser new];
NSError *error = nil;
NSArray *jsonObjects = [jParser objectWithString:myData error:&error];
NSMutableArray *books = [[NSMutableArray alloc] init];
for(NSDictionary *dict in jsonObjects)
{
Book *b = [Book new];
b.bookName =[dict objectForKey:@"name"];
b.published = [dict objectForKey:@"published"];
[books addObject:b];
}
self.bookArray = books;
[self.tableView reloadData];
NSLog(@"myData = %@",myData);
}
私はこれをデバッグする場合、私は私のjsonObjects
を取得し、私のコレクションを移入しています。しかし、私はテーブルがまだ空であることに気付きます。
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
Book *b = (Book *)[self.bookArray objectAtIndex:[indexPath row]];
cell.textLabel.text = b.bookName;
....
誰もが私が欠けている何で私を助けることができます:ちょうどこのことを明確にする
は私tableView
方法ですか?
cellForRowメソッド全体を見てみましょう。 rowsForSectionを実装しましたか? – Dancreek
@DancreekあなたはnumberOfRowsForSectionを意味すると思いますか?とにかく、それと[tableview reloadData]は私がその話題を読んだときの疑いでした。彼はreloadDataを呼び出していますが、後者は不要です。 – barley
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)セクション{ return bookArray.count; } – Matt