我在正在工作的表視圖中加載4個城市字符串,但是當我選擇其中一個單元格並導航到其他表格時,導航速度太慢。我在下面的另一個表中使用了不同鏈接的代碼。你能告訴我爲什麼需要很長時間(〜4 - 6秒)才能看到另一種觀點嗎?在JIT中慢速瀏覽UITableView問題
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL * url = [NSURL URLWithString:@"http://kalkatawi.com/jsonTest.php"];
NSData * data = [NSData dataWithContentsOfURL:url];
NSError *e = nil;
jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&e];
jsonArray1 = [[NSMutableArray alloc] init];
for(int i=0;i<[jsonArray count];i++)
{
NSString * city = [[jsonArray objectAtIndex:i] objectForKey:@"city"];
[jsonArray1 addObject:city];
}
-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
NSString *tempString = [jsonArray1 objectAtIndex:indexPath.row];
cell.textLabel.text = tempString;
return cell;
}
-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SeconfViewController *second = [[SeconfViewController alloc] initWithNibName:@"SeconfViewController" bundle:nil];
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
NSString *edit = [NSString stringWithFormat:@"http://kalkatawi.com/jsonTest.php?d=1&il=%@", cellText];
second.str2 = edit;
[self.navigationController pushViewController:second animated:YES];
}
聽起來像你正在做的是在主線程上進行同步網絡調用。尋找進行異步網絡調用的方法。有很多例子。 –