ios - 在单个 ViewController 上使用多个 Tableview

标签 ios objective-c uitableview

我正在单 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/

相关文章:

iphone - 错误的访问错误我不太明白

objective-c - 当我尝试在 XCode 中运行 Archive 命令时出现问题

android - Flutter - SingleScrollView 不在堆栈/列内滚动

ios 将父级委托(delegate)指定为其子级之一

ios - 在 UITableViewCell 中逐行显示字符串的动画

ios - UITableViewCell 在 didSelectRowAtIndexPath 中比 cellForRowAtIndexPath 短 1px

ios - 自动布局,UiScrollView 内的 UITableView 不会增长

ios - 如何通过FB iOS SDK添加Facebook friend

ios - 是否可以为不同大小的 UIImageView 提供不同的图像

ios - 在 Swift 中以编程方式更改 NSIndexPath