一个View Controller问题中有两个tableView?

时间:2014-03-15 17:27:51

标签: ios objective-c uitableview

我在viewController中实现了两个单独的tableView。其中一个是在按钮上加载的。这个表加载但不显示单元格内容。但是在第二次单击时它会显示内容。这是正确的方法这样做?

这就是我在按钮点击事件上加载tableView的方式。

- (IBAction)barButtonClicked:(id)sender {
     aTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,25 ,200, 150)];
     aTableView.backgroundColor = [UIColor grayColor];
     aTableView.delegate=self;
     aTableView.dataSource=self;
     [[KGModal sharedInstance]showWithContentView:aTableView andAnimated:YES];
 }

这就是我配置tableViews的方式。

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

  static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
     if (tableView.tag==0){.....}
     else if (tableView==aTableView) {

     UIButton *seeButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
     seeButton.frame=CGRectMake(20, 20, 60, 20);
     [seeButton setTitle:@"Show contents" forState:UIControlStateNormal];
     [cell.contentView addSubview:seeButton];
     cell.textLabel.text = [tempArray objectAtIndex:indexPath.row];//After scrolling the table view...crash occurs  here.
}

return cell;
}  

1 个答案:

答案 0 :(得分:0)

尝试强制重新加载barButtonClicked中的数据:

[aTableView reloadData];