IOS:tableview委托两个tableview的方法

前端之家收集整理的这篇文章主要介绍了IOS:tableview委托两个tableview的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在类中的tableview有这些委托方法: @H_404_2@- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array1 count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){ cell = [[[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier] autorelease] ; } cell.textLabel.text = [array1 objectAtIndex:indexPath.row]; return cell; }

如果我有一个UITableView它没关系,但如果我有两个UITableView?我如何组织我的代码?有标签

解决方法

看看所有委托方法如何在其中包含tableView:(UITableView *)tableView?

您可以在头文件中定义表视图,然后只需执行:(假设您的表名为myTable)

@H_404_2@if (tableView == myTable)

然后,您可以拥有任意数量的表视图.

例如:

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

变为:

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

猜你在找的iOS相关文章