我正在单 View Controller 上开发具有多个 TableViews 的 iOS 应用程序。值显示在单个数组的每个 tableview 上。但问题是数组值显示在第一个 TableView 上,而不显示在另一个 TableView 上。有时第二个表格 View 单元格值显示第一个表格 View 。我还尝试处理 tableview 标记值。
code..
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_arrayResult count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if ( tableView == _tableView) { //_clentSelect.tag == 2
MEObject *obj = [_arrayResult objectAtIndex:indexPath.row];
UILabel *dropValue = (UILabel *)[cell viewWithTag:100];
dropValue.text = obj.emp_client_name;
}
if (tableView == _eventSeclect) { //_clentSelect.tag == 2
MEObject *obj = [_arrayResult objectAtIndex:indexPath.row];
UILabel *dropValue = (UILabel *)[cell viewWithTag:1000];
dropValue.text = obj.emp_event_name;
NSLog(@"%@",dropValue.text);
}
// if(_clentSelect.tag == 3) {
//
// MEObject *obj = [_arrayResult objectAtIndex:indexPath.row];
// cell.textLabel.text = obj.emp_client_name;
// }
return cell;
}
最佳答案
- (void)viewDidLoad {
[super viewDidLoad];
//reload your table
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (tableView.tag==1) {
return 1;
}if (tableView.tag==2) {
return 1;
}
else
{
return 0;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView.tag == 1) {
return 10;
}if (tableView.tag == 2) {
returns 20;
}
else{return 0;}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (tableView.tag == 1) {
static NSString *cellIdentifier = @“tbl1”;
cell = [_tbl dequeueReusableCellWithIdentifier:cellIdentifier];
UILabel *title = (UILabel *)[cell viewWithTag:30];
title.text = @"1245";
return cell;
}
if (tableView.tag == 2) {
static NSString *cellIdentifier = @“tbl2”;
cell = [_tbl1 dequeueReusableCellWithIdentifier:cellIdentifier];
UILabel *title = (UILabel *)[cell viewWithTag:30];
title.text = @"1245";
return cell;
}
关于ios - 在单个 ViewController 上使用多个 Tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46091261/