IOS:tableview委托两个tableview的方法

IOS:tableview委托两个tableview的方法,第1张

概述我在类中的tableview有这些委托方法: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {retu 我在类中的tablevIEw有这些委托方法:
- (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)

if (tableVIEw == mytable)

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

例如:

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

变为:

- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {    if (tableVIEw == mytable)    {       return [array1 count];    }    if (tableVIEw == mytable2)    {       return [array2 count];    }    return 0;}
总结

以上是内存溢出为你收集整理的IOS:tableview委托两个tableview的方法全部内容,希望文章能够帮你解决IOS:tableview委托两个tableview的方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1209262.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存