Ios 一个视图中有两个表视图控制器问题?
我在一个viewController中实现了两个独立的表视图。其中一个是在单击按钮时加载的。此表视图加载但不显示单元格内容。但是,在第二次单击时,它会显示内容。正确的方法是什么 这就是我在按钮单击事件中加载tableView的方式Ios 一个视图中有两个表视图控制器问题?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我在一个viewController中实现了两个独立的表视图。其中一个是在单击按钮时加载的。此表视图加载但不显示单元格内容。但是,在第二次单击时,它会显示内容。正确的方法是什么 这就是我在按钮单击事件中加载tableView的方式 - (IBAction)barButtonClicked:(id)sender { aTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,25 ,200, 150)]; aTableVi
- (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];
}
这就是我配置TableView的方式
- (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;
}
尝试在barButtonClicked中强制重新加载数据:
[aTableView reloadData];
如果(tableView==aTableView),我将删除此语句
,并替换为aTableView的标记。如果使用标记,为什么不同时标记两个表视图?如果我从一开始就这样做,我会在viewDidLoad中加载这两个tableView,将aTableView设置为hidden,然后在一个按钮上单击取消隐藏动画。