IOS: tableview delegate methods for two tableview

前端 未结 4 867
暗喜
暗喜 2020-12-31 20:28

I have these delegate method for a tableview inside a class:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)ta         


        
4条回答
  •  春和景丽
    2020-12-31 21:26

    See how all the delegate methods have a tableView:(UITableView *)tableView in them?

    You can define your table views in the header file and then just simply go: (assuming your table is called myTable)

    if (tableView == myTable)
    

    Then you can have as many table views as you like.

    So for example:

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

    Becomes:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        if (tableView == myTable)
        {
           return [array1 count];
        }
        if (tableView == myTable2)
        {
           return [array2 count];
        }
    
        return 0;
    }
    

提交回复
热议问题