iOS 8 UITableViewCell重新排序控件不显示

时间:2014-12-15 02:47:33

标签: ios cocoa-touch uitableview ios8

我最近将我的iPhone和Xcode升级到iOS 8(来自iOS 6),之前在UITableViewCells(在iOS 6中)显示重新排序控件的UITableView不再显示它们,直到我按下删除控件(红圈) )在左侧,此时“删除”按钮从右侧滑过,重新排序控件确实出现在该特定的UITableViewCell上。以下是我在UITableViewDataSource中实现的相关方法。我在UITableViewController上将edit属性设置为YES,在viewDidLoad中设置了UITableView和UITableViewCell,但后两者似乎没有效果,所以我删除了它们。

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
{
    static NSString *CellIdentifier = @"ContactsCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.editingAccessoryType = UITableViewCellAccessoryNone;

    //All but the last cell should show the reorder control
    if (indexPath.item < contacts.count)
    {
        cell.textLabel.text = [contacts contactNameAtIndex: indexPath.item];
        cell.textLabel.textColor = [UIColor blackColor];
        cell.textLabel.font = [UIFont systemFontOfSize: 18];
        cell.textLabel.adjustsFontSizeToFitWidth = YES;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.showsReorderControl = YES;
    }
    else
    {
        cell.textLabel.text = @"Add a contact";
        cell.textLabel.textColor = [UIColor grayColor];
        cell.textLabel.font = [UIFont systemFontOfSize: 16];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.showsReorderControl = NO;
    }

    return cell;
}

- (BOOL) tableView: (UITableView *) tableView canMoveRowAtIndexPath: (NSIndexPath *) indexPath
{
    return indexPath.item < contacts.count; //All but the last cell can be reordered
}

- (void) tableView: (UITableView *) tableView moveRowAtIndexPath: (NSIndexPath *) fromIndexPath toIndexPath: (NSIndexPath *) toIndexPath
{
    [contacts moveContactAtIndex: fromIndexPath.item ToIndex: toIndexPath.item];
}

谢谢,

Vatche

0 个答案:

没有答案