添加新单元格后,UITableViewCell不会突出显示

时间:2012-10-01 04:12:40

标签: ipad uitableview

我是SplitViewControllers的新手,我不确定我是否在做一些内在错误的事情。所以我有一个加号按钮,为我的NSManagedObjectModel添加一个新对象。在该代码中,我尝试设置添加到选定或突出显示的最后一个单元格。我不确定我想要哪个。我想我想要突出显示,因为我想给用户提供视觉提示,即最后添加的对象。我希望将该对象设置为当前属性,所以我认为选择也可以。在任何情况下,我都尝试了两种方法,但似乎没有突出显示该行。所以这些是我尝试的一些事情:

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

    switch (type) {
            // Data was inserted - insert the data into the table view
        case NSFetchedResultsChangeInsert: {
            [self.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
//            [cell setHighlighted:YES animated:YES];
            [cell setSelected:YES animated:YES];

            break;
        }
            // Data was deleted - delete the data from the table view
        case NSFetchedResultsChangeDelete: {
            NSIndexSet *setToDelete = [NSIndexSet indexSetWithIndex:indexPath.section];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

            if ([controller.fetchedObjects count] == 0) {
                [self.tableView deleteSections:setToDelete withRowAnimation:UITableViewRowAnimationAutomatic];
            }

            break;
        }
        case NSFetchedResultsChangeUpdate: {
            [self configureCell:(MapListTableViewCell_iPad *)[self.tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;
        }
        case NSFetchedResultsChangeMove: {
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            [self.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            break;
        }
        default:
            break;
    }
}

// This method is called when a new item is inserted
- (void)mapViewController_iPad:(MapViewController_iPad *)vc didInsertMap:(Map *)map {
    NSIndexPath *indexPath = [self.fetchedResultsController indexPathForObject:map];

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    [cell setHighlighted:YES animated:YES];
}

按下+时调用此方法:

- (IBAction)addMap:(id)sender {
    NSString *mapName = @"New Map";
    Map *aMap = [Map mapWithName:mapName region:self.mapViewController_iPad.region inManagedObjectContext:self.managedObjectContext];
    self.map = aMap;

    NSIndexPath *indexPath = [self.fetchedResultsController indexPathForObject:aMap];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    [cell setSelected:YES animated:YES];
    [cell setHighlighted:YES animated:YES];

    [self saveContext];
}

这些都没有突出显示刚刚添加的UITableViewCell。谁知道我做错了什么?谢谢!

0 个答案:

没有答案