uitableview

【原/转】UITableview性能优化总结

限于喜欢 提交于 2020-01-21 23:57:29
UITableView作为ios中使用最频繁的控件之一,其性能优化也是常常要面对的,尤其是当数据量偏大并且设备性能不足时。本文旨在总结tableview的几个性能优化tips,并且随着认识的深入,本文将持续更新,力求将tableview的优化做到极致! Let`s begin! 治病就要先知道病因,我们先来分析一下影响tableview滚动性能的因素有哪些: 1、cellForRowAtIndexPath方法中处理了过多业务 2、tableviewCell的subview层级太复杂,做了大量透明处理 3、cell的height动态变化时计算方式不对 前面两点比较好理解,本文着重处理第三种情况。 想要对tableview做性能优化,只能从tableview的数据源方法入手,纵观这些方法,主要有两个方法可以为我们所用:cellForRow以及heightForRow。我们一一分析: (1)heightForRowAtIndexPath 很多人都把优化的重点放到了 cell for row at indexpath 那个方法里了,在这里尽可能的少计算,但是却忽略了另一个很轻松就能提升加载时间的方法 : - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

UIButton not responding used in a custom UITableViewCell

旧时模样 提交于 2020-01-21 12:44:14
问题 I know this issue is already been asked few times in SO. Despite trying those out, I am still unable to solve my problem. I am using a UITableView inside a UIViewController. I have a custom UITableViewCell which has couple of buttons in it. However, I am not able to make the Button respond to Click event. The development environment is iOS 9 and Swift 2 Snippets used : BranchNearMeTableViewCell.swift contains @IBOutlet weak var btnDetails: UIButton! view controller class func tableView

Don't reuse cell in UITableView

梦想与她 提交于 2020-01-21 11:39:13
问题 let cell = tableView.dequeueReusableCellWithIdentifier("cellReuseIdentifier", forIndexPath: indexPath) as! CustomTableViewCell I don't want to reuse the cells once the cell is created, I want it to be available in memory. 回答1: It's your decision of course, but it's a very bad idea. Unless you have less than 10 cells in your tableView and you are 100% sure there will be no more cells. Otherwise the app will crash on memory pressure pretty fast. Just don't dequeue cells. Create new each time:

Swift 3 : URL Image makes UITableView scroll slow issue

五迷三道 提交于 2020-01-21 05:25:12
问题 I have an extension to print image URL on UIImageView . But I think the problem is my tableView is so slow because of this extension. I think I need to open thread for it. How can I create a thread in this extension or do you know another solution to solve this problem? My code : extension UIImageView{ func setImageFromURl(stringImageUrl url: String){ if let url = NSURL(string: url) { if let data = NSData(contentsOf: url as URL) { self.image = UIImage(data: data as Data) } } } } 回答1: I think,

Why doesn't UITableViewCell background color work (set in interface builder)?

自作多情 提交于 2020-01-20 12:54:05
问题 Why doesn't UITableViewCell background color work (set in interface builder)? I note from some searching that the follow code set in your custom subclass of UITableViewController does work (see below): - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor redColor]; } But I would still like to just understand why interface builder has a background color setting for the TableViewCell,

UITableView with controller separate from ViewController

ぐ巨炮叔叔 提交于 2020-01-20 08:54:47
问题 I'm a newbie to Swift and XCode, taking a class in iOS development this summer. A lot of projects we're doing and examples I'm seeing for UI elements like PickerViews, TableViews, etc. are defining everything in the ViewController.swift file that acts as the controller for the main view. This works fine, but I'm starting to get to the point of project complexity where I'd really like all of my code to not be crammed into the same Swift file. I've talked to a friend who does iOS development on

UITableView with controller separate from ViewController

倖福魔咒の 提交于 2020-01-20 08:53:06
问题 I'm a newbie to Swift and XCode, taking a class in iOS development this summer. A lot of projects we're doing and examples I'm seeing for UI elements like PickerViews, TableViews, etc. are defining everything in the ViewController.swift file that acts as the controller for the main view. This works fine, but I'm starting to get to the point of project complexity where I'd really like all of my code to not be crammed into the same Swift file. I've talked to a friend who does iOS development on

UISearchController search bar overlap first cell when active

给你一囗甜甜゛ 提交于 2020-01-20 08:44:25
问题 I am using UISearchController to search for data in my tableview. I am not using table view controller. I would like to hide the navigation bar when my search bar is active therefore I set self.searchController.hidesNavigationBarDuringPresentation = YES; to yes. However when I do this and want to search, my active search bar covers part of the first cell. the covered part has same height as status bar. I tried other articles and questions similar to this one but nothing helped me to solve it.

slow scrolling of UITableView [duplicate]

☆樱花仙子☆ 提交于 2020-01-20 07:08:47
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: UIImage in uitableViewcell slowdowns scrolling table I filled my table view data with plist file which will download from a server . but after user scrolls the table the scrolling is very slow ! this is my code : //this is my plist code that load from server NSURL *url = [NSURL URLWithString:@"http://example.com/news.plist"]; titles = [[NSArray arrayWithContentsOfURL:url] retain]; tableview : - (NSInteger

How to make UITableView Header selectable?

Deadly 提交于 2020-01-20 03:51:53
问题 I have made a custom section-header for UITableView, that includes some controls like segmented control, UIImageView ,etc. It successfully appears, but it's not tappable so I can't interact with its controls. I need to know how can I make this header view selectable? 回答1: There is no way to do it with the UITableViewDelegate. You have to add a UITapGestureRecognizer to yourHeaderView Like: UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action