bluetooth99 2013-06-03 08:06 采纳率: 0%
浏览 3020
已采纳

UITableView从jsonURL加载数据

在UITableview的JSON的URL绑定数据,但是在执行过程中报错。

NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
statuses = [parser objectWithString:json_string error:nil];
[self.dropdownTblView reloadData];
for (NSDictionary *status in statuses) 
{
    _altTitle = [status valueForKey:@"Title"];
    NSLog(@"Title %@",_altTitle);
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   NSLog(@"%d",[statuses count]);
   return [statuses count];

}

- (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];
}
return cell;

 //Here I'm getting an error    
id obj = [statuses objectAtIndex:indexPath.row];
NSString *name = [obj valueForKey:@"Title"];
cell.textLabel.text =name;
return cell;
}

JSON内容:

[
  {
    "Id": 1,
    "Title": "Tamil to English",
    "AltTitle": "த|மி|ழ்| |மூ|ல|ம்| |ஆ|ங்|கி|ல|ம்",
    "Description": "Learn English through Tamil",
    "Code": 1,
    "Version": "1.0",
    "SourceLanguageIndicator": "அ",
    "TargetLanguageIndicator": "A",
    "SourceLanguageCode": "ta",
    "TargetLanguageCode": "en",
    "Updated": "2013-02-21T03:33:19.6601651+00:00"
  }    
]    
  • 写回答

2条回答 默认 最新

  • ReyZhang 移动开发领域新星创作者 2013-06-03 08:28
    关注

    上面的代码在未执行到你报错的地方的时候,就返回了吧

    return cell; //这一句直接就返回了.不会执行下面的代码.
    
     //Here I'm getting an error    
    id obj = [statuses objectAtIndex:indexPath.row];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100