在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"
}
]
上面的代碼在未執行到你報錯的地方的時候,就返回了吧
return cell; //這一句直接就返回了.不會執行下面的代碼.
//Here I'm getting an error
id obj = [statuses objectAtIndex:indexPath.row];