我正在开发我的第一个应用程序并开始将我的头撞到墙上。我创建了一个可以输出简单 JSON 的 C# Web API。我正在使用 AFNetworking 并获得有效响应(我相信),现在我想获取这个 JSON 对象并将其转换为 UITable。这是代码。
这是在我看来确实加载了。
- (void)viewDidLoad
{
[super viewDidLoad];
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"SMP" accessGroup:nil];
NSString *password = [keychain objectForKey:(__bridge id)(kSecValueData)];
NSString *username = [keychain objectForKey:(__bridge id)(kSecAttrAccount)];
[[APIClient sharedManager] setUsername:username andPassword:password];
[[APIClient sharedManager] getPath:@"/api/leads_calls/?$top=5&$orderby=CallStart%20desc"parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.leads_dict = responseObject;
self.leads_calls = [[NSMutableArray alloc] init];
[self.leads_calls addObject:self.leads_dict];
NSLog(@"%@", self.leads_calls);
[self.tableView setHidden:NO];
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// error stuff here
}];
}
我可以在以下代码中设置断点,然后引发异常:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (self.leads_calls > nil) {
// Here is where I get the exception
cell.textLabel.text = [[self.leads_calls objectAtIndex:indexPath.row] objectForKey:@"CallerName"];
}
return cell;
}
最后,我在异常时的数组如下所示:
2013-06-06 14:32:11.372 SMP[39846:c07] (
(
{
CallEnd = "2013-06-06T12:20:26";
CallStart = "2013-06-06T12:11:56";
CallerName = "xx & xx";
CallerNo = xxxxxxxxxx;
Handled = 0;
ID = 1134514;
},
{
CallEnd = "2013-06-06T11:36:41";
CallStart = "2013-06-06T11:07:43";
CallerName = "Las xx NV";
CallerNo = xxxxxxxxxx;
Handled = 0;
ID = 1134333;
},
{
CallEnd = "2013-06-04T13:09:00";
CallStart = "2013-06-04T12:58:36";
CallerName = "xx LAW FI";
CallerNo = xxxxxxxxxx;
Handled = 0;
ID = 1129882;
},
{
CallEnd = "2013-06-03T16:43:31";
CallStart = "2013-06-03T16:32:32";
CallerName = "xx xx";
CallerNo = xxxxxxxxxx;
Handled = 0;
ID = 1127940;
},
{
CallEnd = "2013-06-03T07:46:16";
CallStart = "2013-06-03T07:44:23";
CallerName = "xx x";
CallerNo = xxxxxxxxxx;
Handled = 0;
ID = 1125648;
}
)
)
我会四处走动,猜测 cell.textLabel.text 正在获得一个它不期望的值,但我不知道如何解决这个问题。