程序在下面的註釋行崩潰。不知道有什麼問題。第一次程序員的任何提示?ObjectAtIndex崩潰
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"];
}
cell.textLabel.text = [[users objectAtIndex:indexPath.row] objectForKey:[[NSString alloc] initWithFormat:@"%d", indexPath.row]];
//My program runs but then crashes at this line, I have no idea what's wrong with it though "reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance"
return cell;
}
更多的代碼(不是所有的它雖然)的要求
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
users = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
[self.tableView reloadData];
}
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [users count];
}
在.h文件中
@interface GIFUsersListViewController : UITableViewController {
NSArray *users; NSMutableData *data;
} @end
雖然你可能*認爲*用戶是Array的編譯器錯誤是告訴你它不是。編譯器是正確的。 – MarkPowell 2013-02-18 00:25:09
用戶顯然實際上是一個NSDictionary,而不是你所期望的。您應該在用戶創建的地方發佈代碼。 – 2013-02-18 00:26:11
好的。我會發布更多的代碼,所以看起來像這個部分是好的 - 因爲這是我得到一個綠色的SIGARBT標誌 – GangstaGraham 2013-02-18 00:27:44