简体   繁体   English

NSMutableArray:count是方法还是属性?

[英]NSMutableArray: count is a method or a property?

I want to verify if I'm in the last cell of the UITable. 我想验证我是否在UITable的最后一个单元格中。 Should I use a NSInteger property in my controller and store the value of the count of the data (it's an NSMutableArray) that populates the table? 我应该在我的控制器中使用NSInteger属性并存储填充表的数据计数值(它是一个NSMutableArray)吗?

I'm asking because I don't know if count iterates over all objects of the array to count or if it only gets me a value of a count property. 我问,因为我不知道count是否迭代数组的所有对象来计算,或者它是否只获得count属性的值。

What would be better ? 什么会更好?

store the value: myCount = [myArray count] 存储值:myCount = [myArray count]
use directly: [myArray count] 直接使用:[myArray count]
store numberOfRows: myCount = numberOfRowsInSection:[indexPath 0] store numberOfRows:myCount = numberOfRowsInSection:[indexPath 0]
use numberOfRows directly: numberOfRowsInSection:[indexPath 0] 直接使用numberOfRows:numberOfRowsInSection:[indexPath 0]

Use the method directly. 直接使用该方法。 It is almost certainly efficient enough. 它几乎肯定足够有效。 If you are having serious performance problems, use shark and instruments to discover why. 如果您遇到严重的性能问题,请使用鲨鱼和器械来发现原因。 If you see most of your time is being spent in calls to count, find a way to optimize that, like you suggested here. 如果你看到你的大部分时间都花在了数字的调用上,那就找到一种方法来优化它,就像你在这里建议的那样。 But don't optimize prematurely like this--you are just wasting your time even thinking about it. 但是不要像这样过早地进行优化 - 你只是在浪费你的时间来思考它。

因为表视图的状态可以随时更改,具体取决于iPhone OS在任何给定时间执行的操作,您几乎总是希望从模型中提取状态数据(在本例中为数组)。

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

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