在 iOS 中滚动时禁用 uitableview 禁用重用

Disable uitableview disable reuse when scrolling in iOS

我想禁用滚动时重新加载 table 视图。现在,当用户滚动 uitable 视图时,我的应用程序已调用 cellForRowAtIndexPath。

viewDidLoad 中的内容

[listingTableView registerNib:[UINib nibWithNibName:@"TripCardCell" bundle:nil] forCellReuseIdentifier:[TripCardCell cellID]];

cellForRowAtIndexPath 中的内容

if (cell == nil) {
        cell = [[TripCardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[TripCardCell cellID]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

UITableViewCell Class Reference

The reuse identifier is associated with a UITableViewCell object that the table-view’s delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter. A UITableView object maintains a queue (or list) of the currently reusable cells, each with its own reuse identifier, and makes them available to the delegate in the dequeueReusableCellWithIdentifier: method.

reuseIdentifiers的优势

Using dequeueReusableCellWithIdentifier for the tableView, you can greatly speed things up. Instead of instantiating a lot of cells, you just instantiate as many as needed, i.e. as many that are visible (this is handled automatically). If scrolling to an area in the list where there are "cells" that haven't got their visual representation yet, instead of instantiating new ones, you reuse already existing ones.

滚动时禁用重新加载表格视图

You cannot block the cellForRowAtIndexPath: from calling when scrolling the tableview. If something need not happen every time, You may keep it in if condition.

 if (cell == nil)
    {
        //Functionality goes here when it not needed to happen every time.
    }