在iOS6中重新加载tableview无法正常工作

时间:2013-12-02 16:33:00

标签: objective-c uitableview ios6

我开发了一个简单的应用程序,我必须根据用户在另一个viewcontroller中选择的选项对tableview进行排序。到目前为止一切都很好,因为iOS 7它运行完美,但iOS6上运行的相同代码却没有。由于应用程序非常简单,我想与iOS6保持兼容,所以对于排序之后的这个,我使用方法tableview.reload,但我没有成功使用iOS 6.有没有办法解决方法这个问题并保持兼容两个平台??

1 个答案:

答案 0 :(得分:1)

要调用的方法是:

[tableView reloadData];

我不知道tableView.reload是什么,但是不要使用点表示法调用void返回方法。我不知道这是否有效,但它太糟糕了。

为我这样做:

将它放在#imports:

下的文件顶部
static NSString *const CellIdentifier = @"ThisIsAUniqueID";

初始化/配置tableView时,请执行以下操作:

[self.tableView registerClass:[UITableViewCell class] forCellWithReuseIdentifier:CellIdentifier];

cellForRow:方法中执行此操作:

/**
 *  Asks the data source for a cell to insert in a particular location of the table view.
 *
 *  @param  tableView                   A table-view object requesting the cell.
 *  @param  indexPath                   An index path locating a row in tableView.
 *
 *  @return An object inheriting from UITableViewCell that the table view can use for the specified row.
 */
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    UILabel *label = [tableView viewWithTag:1];
    label.text = sortedArray[indexPath.row];
    return cell;
}
相关问题