简体   繁体   English

如何调用从UITableView的委托方法

[英]How to call method from UItableview delegate

1) My problem: how to call NumberofRowsInSection of UItableViewDataSource Method of another UItableViewdataSource. 1)我的问题:如何调用另一个UItableViewdataSource方法的UItableViewDataSource方法的NumberofRowsInSection。

2 ) HOw to make aggrateTableViewDataSource from n number of Different CustomTableViewDataSource? 2)如何从n个不同的CustomTableViewDataSource中制作aggrateTableViewDataSource?

Need Help. 需要帮忙。 Thanks 谢谢

I think there is some conceptional confusion in your question. 我认为您的问题中存在一些概念上的混乱。

datasource is a delegate protocol . datasource委托协议 That means that you can have a class that adopts that protocol. 这意味着您可以拥有一个采用该协议的 That again means that it has certain required or optional methods, eg tableView:numberOfRowsInSection: in the case of the protocol UITableViewDataSource . 这再次意味着它具有某些必需的或可选的方法,例如,对于协议UITableViewDataSource而言,它是tableView:numberOfRowsInSection: UITableViewDataSource

Therefore there is no such thing as "two datasources". 因此,不存在“两个数据源”之类的东西。 If your class that implements the datasource protocol has more than one source for its data, that's a different kind of "data source" - and a question completely unrelated to the datasource protocol for table views. 如果您实现数据源协议的类具有多个数据源,则这是另一种“数据源”,这是与表视图的datasource协议完全无关的问题。

Of course, you can have more than one UITableView that refers to the same class as its datasource . 当然,可以有多个 UITableView与其datasource引用同一类。 This is actually common for search tables which typically can display both the original and the search result table. 这实际上对于通常可以同时显示原始表和搜索结果表的搜索表很普遍。 In this case, you check in your datasource methods which table view is requesting the data. 在这种情况下,您可以在数据源方法中检入哪个表视图正在请求数据。

I would suggest to make a model that calculates this from the source, not the tables. 我建议创建一个模型,该模型从源而不是从表中进行计算。 If you are using core data, create a class that fetches the objects and calculates the figures then observes changes to update the basis for the figures. 如果使用的是核心数据,请创建一个类,以获取对象并计算图形,然后观察更改以更新图形的基础。 Make your aggregate functions output as read only properties. 使聚合函数输出为只读属性。 If not core data use, I'd need more info to advise. 如果不使用核心数据,我需要更多信息来建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM