我一直在嘗試幾個小時來弄清楚這一點。我有一個來自NSURLConnection的JSON。這工作正常,我已經解析成一個數組。但我似乎無法從connectionDidFinishLoading方法中獲取數組。我在UITableViewCell方法中獲取(null)。我認爲這是一個保留問題的範圍,但我對於ObjC來說是如此的新鮮,我不知道該怎麼做。任何幫助將不勝感激。
乾杯。從連接添加iPhone UITableViewDDFinishLoading
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
SBJSON *json = [[SBJSON alloc] init];
NSDictionary *results = [json objectWithString:responseString];
self.dataArray = [results objectForKey:@"data"];
NSMutableArray *tableArray = [[NSMutableArray alloc] initWithObjects:nil];
for (NSString *element in dataArray) {
//NSLog(@"%@", [element objectForKey:@"name"]);
NSString *tmpString = [[NSString alloc] initWithString:[element objectForKey:@"name"]];
[tableArray addObject:tmpString];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
//cell.textLabel.text = [self.tableView objectAtIndex:indexPath.row];
cell.textLabel.text = [self.tableArray objectAtIndex:indexPath.row];
NSLog(@"%@", tableArray);
return cell;
}
kubi。 我試過這種方式,我仍然在UITableVIewCell方法中爲null?但是我在connectionDidFinishLoading中獲得了正確的值。它仍然陷在那裏... 感謝您的幫助。 –
我注意到: 2010-02-06 13:38:07.907課程[34368:207](null) 2010-02-06 13:38:07.908課程[34368:207](null) 2010-02 -06 13:38:07.910課程[34368:207](null) 2010-02-06 13:38:07.952課程[34368:207]( 「我的高爾夫球場」, 「Glen Annie」, 「Alisal牧場「, 」聖巴巴拉高爾夫俱樂部「, 」蘭喬聖馬科斯「 ) UITableViewCell似乎在connectionDidFinishLoading之前加載。所以價值觀還不存在...... –