Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从另一个未工作的UIVIewController中选择RowatineXpath_Ios_Objective C_Uitableview_Uiviewcontroller - Fatal编程技术网

Ios 从另一个未工作的UIVIewController中选择RowatineXpath

Ios 从另一个未工作的UIVIewController中选择RowatineXpath,ios,objective-c,uitableview,uiviewcontroller,Ios,Objective C,Uitableview,Uiviewcontroller,我试图在UITableView上调用SelectRowatineXpath,该UITableView是我调用它的UIViewController的子视图 我已经对其进行了设置,这样当您选择一个单元格时,它会变成灰色,这很好,但是我正在将不同的数据集加载到UITableView中或从UITableView中加载,并且在进行任何选择时,我都会将所选NSIndexPath发送回UIViewController。然后,当视图下一次加载nsindepath的正确数据集时,我从UIViewControlle

我试图在UITableView上调用SelectRowatineXpath,该UITableView是我调用它的UIViewController的子视图

我已经对其进行了设置,这样当您选择一个单元格时,它会变成灰色,这很好,但是我正在将不同的数据集加载到UITableView中或从UITableView中加载,并且在进行任何选择时,我都会将所选NSIndexPath发送回UIViewController。然后,当视图下一次加载nsindepath的正确数据集时,我从UIViewController调用此方法

if (codeIndexPath != nil) {
            [filterViewController.tableView selectRowAtIndexPath:codeIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
然后在UITableView类中,我的单元格用于rowatindexpath选择了rowatindexpath如下所示

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    NSString *projectDescriptionString = [currentFilterMutableArray objectAtIndex:indexPath.row];
    cell.textLabel.text = projectDescriptionString;
    if (indexPath == currentlySelectedIndex) {
        cell.highlighted = YES;
    } else if (indexPath == currentlySelectedIndex) {
        cell.highlighted = NO;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    cell.selectionStyle = UITableViewCellSelectionStyleGray;

    // send this data back in the delegate so you can use it to show where the tick is again if you need too.
    currentlySelectedIndex = indexPath;

    [[self delegate] updateInstallTableWithFilter:[currentFilterMutableArray objectAtIndex:indexPath.row] FilterType:filterType InstallIndex:indexPath];

}
当它加载到屏幕上时,正确的单元格将高亮显示一秒钟,然后返回白色

使现代化 CellForRowatineXpath内的新if语句

if ([indexPath isEqual:currentlySelectedIndex]) {
        cell.highlighted = YES;
    } else if (![indexPath isEqual:currentlySelectedIndex]) {
        cell.highlighted = NO;
    }

我仍然收到相同的错误。

UITableViewController有一个名为
ClearSelectionInviewMillAppear的属性

当第一次加载表视图时,将显示 表视图控制器重新加载表视图的数据。它还清除了 其选择(有或没有动画,取决于请求) 每次显示表格视图时。UITableViewController 类在超类方法viewWillAspect中实现此功能:。你 可以通过更改中的值来禁用此行为 清除SelectionInviewMillAppear属性

所以在表视图控制器子类中,在viewDidLoad中

- (void)viewDidLoad {
    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
}

UITableViewController有一个名为
ClearSelectionInviewMillAppear
的属性:

当第一次加载表视图时,将显示 表视图控制器重新加载表视图的数据。它还清除了 其选择(有或没有动画,取决于请求) 每次显示表格视图时。UITableViewController 类在超类方法viewWillAspect中实现此功能:。你 可以通过更改中的值来禁用此行为 清除SelectionInviewMillAppear属性

所以在表视图控制器子类中,在viewDidLoad中

- (void)viewDidLoad {
    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
}

您不应该将indexpath与“==”进行比较,因为它们是对象。您应该使用isEqual:代替。不仅是if和else if都==lol错过了那一个。。我更新了它。。将在一秒钟内显示新代码。您不应该将IndExpath与“==”进行比较,因为它们是对象。您应该使用isEqual:代替。不仅是if和else if都==lol错过了那一个。。我更新了它。。将在一秒钟内显示新代码。哇。。我已经尝试了很多东西,我有点迷失在这一切。。。哦,我今天学到了一些新东西,希望下次我能记住。哈哈,非常感谢你的帮助。哇。。我已经尝试了很多东西,我有点迷失在这一切。。。哦,我今天学到了一些新东西,希望下次我能记住。哈哈,非常感谢你的帮助。