Search code examples
objective-cuitableviewios6

Reload tableview in iOS6 does not work properly


I have developed a simple app where I have to sort a tableview according to the option the user picks in another viewcontroller. So far so good because with iOS 7 it is working perfect, however the same code running on iOS6 isn't. As the app is pretty simple I'd like to keep compatible also with the iOS6, so for this after the sort, I am using the method tableview.reload, but I am not having success with iOS 6. Is there a way to workaround this issue and keep compatible for both platforms??


Solution

  • The method to call is:

    [tableView reloadData];
    

    I don't know what tableView.reload is, but don't call a void returning method with dot notation. I don't know if that even works, but it's awful.

    Do this for me:

    Place this at the top of the file under the #imports:

    static NSString *const CellIdentifier = @"ThisIsAUniqueID";
    

    When initialising/configuring the tableView do this:

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

    In the cellForRow: method do this:

    /**
     *  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;
    }