Ios tableview默认选定单元格

Ios tableview默认选定单元格,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我使用下面的代码在UITableView中显示核心数据表 我假设您知道要选择的索引? 对于找到正确的组 否则,您需要一个for循环才能在fetchedResults中找到它 // for loop around _group to find the index NSInteger index = -1; for (NSInteger i = 0; i < [_group count]; i++) { NSManagedObject *groups = [_group ob

我使用下面的代码在UITableView中显示核心数据表


我假设您知道要选择的索引? 对于找到正确的

否则,您需要一个for循环才能在fetchedResults中找到它

 // for loop around _group to find the index

NSInteger index = -1;

for (NSInteger i = 0; i < [_group count]; i++) {

    NSManagedObject *groups = [_group objectAtIndex:i];

    if (selectedgroup != nil && groups == selectedgroup) {

        index = i;
        break;
    }
}

if (index != -1)
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
//供循环组查找索引
NSInteger指数=-1;
对于(NSInteger i=0;i<[u组计数];i++){
NSManagedObject*组=[\u组对象索引:i];
if(selectedgroup!=nil&&groups==selectedgroup){
指数=i;
打破
}
}
如果(索引!=-1)
[self.tableView SelectRowatineXpath:[NSIndexPath indexPathForRow:索引位置:0]动画:无滚动位置:UITableViewScrollPositionTop];

我还假设您只有一个部分,因为您正在为indexPath.row提取托管对象。您需要澄清您的问题。不清楚您想做什么。我的表视图与NSManagedObjects(组)绑定,现在我想默认选择一个组我将“selectedgroup”从另一个视图控制器传递到组tableviewcontroller,如果“selectedgroup”,我想签入组tableviewcontroller存在然后选择组中的表视图视图视图中出现了对不起我的错误它工作得很好,非常感谢Magoo