开发者社区 问答 正文

关于UITableView从jsonURL加载数据 的问题

UITableviewJSONURL绑定数据,但是在执行过程中报错。

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"
  }    
]    

展开
收起
爵霸 2016-03-19 11:55:26 1740 分享 版权
1 条回答
写回答
取消 提交回答
  • 面的代码在未执行到你报错的地方的时候,就返回了吧
    return cell; //这一句直接就返回了.不会执行下面的代码.

     //Here I'm getting an error    
    id obj = [statuses objectAtIndex:indexPath.row];
    2019-07-17 19:07:58
    赞同 展开评论
问答分类:
问答地址: