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时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器