【问题标题】:reloadData on tableView crashes when used with uisplitviewController inside a tabbar controller与标签栏控制器内的 uisplitviewController 一起使用时,tableView 上的 reloadData 崩溃
【发布时间】:2012-09-15 23:43:34
【问题描述】:

我正在使用标签栏应用程序。在其中一个选项卡中,我将 tableView 控制器嵌入为 SplitView。当此选项卡变为活动状态时,我会进行 URL 调用以从服务器获取一些数据。我无法在 tableView 中填充数据。我试过'[self.tableView reloadData]',但应用程序崩溃了。我的 ViewController 类是 UITableViewController 的子类。

- (void)didReceiveUserListFromServer
{
NSData *jsonData = responseData;
NSError *error=nil;

NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONWritingPrettyPrinted error:&error];
userDetailsArray = [responseDict objectForKey:@"userDetails"];
NSLog(@"count===%d",[userDetailsArray count]);   //This returns a non-zero number
[self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [userDetailsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"ReturningPatientSearchResultCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}



NSMutableDictionary *singleUserDetail = [userDetailsArray objectAtIndex:indexPath.row];
cell.textLabel.text=[singleUserDetail objectForKey:@"Name"];  //EXC_BAD_ACCESS here

return cell;
}

【问题讨论】:

  • 如果您在崩溃前记录singleUserDetailuserDetailsArray 的值,您会看到什么?
  • @PhillipMills 它在没有记录任何值的情况下崩溃。

标签: ipad uitabbarcontroller uitableview uisplitviewcontroller ios5.1


【解决方案1】:

我会尝试在您的类中将userDetailsArray 设为strong 属性,并使用self.userDetailsArray 设置其值和对其的引用。

(奇怪的是,该数组对count 有效,但对以后的访问无效,但释放的内存似乎是最合乎逻辑的解释。)

您也可以尝试为您的构建方案启用僵尸,看看是否能提供更好的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    相关资源
    最近更新 更多