这对于桌面视图有效吗?
我只是想澄清这是为我的表格视图中的单元格制作标题数组的最简单且最有效的方法。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
contentArray = [[NSArray arrayWithObjects:@"Hi1", @"Hi2", @"Hi3", @"Hi4", @"Hi5", @"Hi6", @"Hi7", nil] retain];
return [contentArray count];
[contentArray release];
}
我应该以另一种方式来做这件事,还是应该以这种高效且最好的方式来做?因为目前它有点滞后,我想让它更快一点。
谢谢!
I am just trying to clarify that this is the easiest and most efficient way to make the array of titles for the cells in my tableview.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
contentArray = [[NSArray arrayWithObjects:@"Hi1", @"Hi2", @"Hi3", @"Hi4", @"Hi5", @"Hi6", @"Hi7", nil] retain];
return [contentArray count];
[contentArray release];
}
Should I be doing this another way or this efficient and the best it can be? Because currently it is a bit laggy and I would like to make it a bit faster.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对
tableView:numberOfRowsInSection:
方法的调用可以由不同的事件触发。您在每次调用时创建数组,这会增加延迟。试试这个:Calls to the method
tableView:numberOfRowsInSection:
can be triggered by different events. You are creating the array on each call, which increases the lag. Try this instead:您在此方法中所做的操作对表视图的滚动性能几乎没有任何影响,因为它只会被调用非常有限的次数(除非您的表包含数百或数千个部分)。
也就是说,您的代码包含许多错误。首先,
return
下面的行永远不会执行,因此存在内存泄漏。其次,您应该在方法外部创建数组并使用属性来存储它。但这与性能关系不大,而与良好的编码风格关系更大。毕竟,您将在多种方法中需要数组的内容。What you do in this method has pretty much no influence at all on the scrolling performance of your table view because it is only going to be called a very limited number of times (unless your table contains hundreds or thousands of sections).
That said, your code contains many errors. Firstly, the line below
return
is never executed so you have a memory leak. Secondly, you should create the array outside the method and use a property to store it. But that has less to do with performance and more with good coding style. After all, you will need the contents of the array in multiple methods.