Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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
Iphone 选择行以更改视图_Iphone_Objective C - Fatal编程技术网

Iphone 选择行以更改视图

Iphone 选择行以更改视图,iphone,objective-c,Iphone,Objective C,我已经创建了视图控制器,并附加这些控制器来控制各自的视图。但是,我不知道如何使以下代码进入正确的视图(在根视图控制器中): 每次我选择表中的任何一行时,所有视图都会出现。我如何安排它们只打开它应该打开的视图?问题是您在每个视图控制器上调用pushViewController:animated。如果您只想显示一个视图控制器,只需对所需的视图控制器调用pushViewController:animated。以下是一个示例: - (void)tableView:(UITableView *)table

我已经创建了视图控制器,并附加这些控制器来控制各自的视图。但是,我不知道如何使以下代码进入正确的视图(在根视图控制器中):


每次我选择表中的任何一行时,所有视图都会出现。我如何安排它们只打开它应该打开的视图?

问题是您在每个视图控制器上调用
pushViewController:animated
。如果您只想显示一个视图控制器,只需对所需的视图控制器调用
pushViewController:animated
。以下是一个示例:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath*)indexPath {

    // This code shows a different view depending on the selected row.
    UIViewController *viewController = nil;
    switch (indexPath.row) {
        case 0:
            viewController = [[RunViewController alloc] initWithNibName:@"RunView" bundle:[NSBundle mainBundle]];
            break;

        case 1:
            viewController = [[CalcViewController alloc] initWithNibName:@"CalcView" bundle:[NSBundle mainBundle]];
            break;

        case 2:
            viewController = [[PushViewController alloc] initWithNibName:@"PushView" bundle:[NSBundle mainBundle]];
            break;

        case 3:
            viewController = [[SitViewController alloc] initWithNibName:@"SitView" bundle:[NSBundle mainBundle]];
            break;

        case 4:
            viewController = [[TimerViewController alloc] initWithNibName:@"TimerView" bundle:[NSBundle mainBundle]];
            break;
    }

    if (viewController != nil) {
        [self.navigationController pushViewController:viewController animated:YES];
        [viewController release];
    }

}

问题在于,您正在对每个视图控制器调用
pushViewController:animated
。如果您只想显示一个视图控制器,只需对所需的视图控制器调用
pushViewController:animated
。以下是一个示例:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath*)indexPath {

    // This code shows a different view depending on the selected row.
    UIViewController *viewController = nil;
    switch (indexPath.row) {
        case 0:
            viewController = [[RunViewController alloc] initWithNibName:@"RunView" bundle:[NSBundle mainBundle]];
            break;

        case 1:
            viewController = [[CalcViewController alloc] initWithNibName:@"CalcView" bundle:[NSBundle mainBundle]];
            break;

        case 2:
            viewController = [[PushViewController alloc] initWithNibName:@"PushView" bundle:[NSBundle mainBundle]];
            break;

        case 3:
            viewController = [[SitViewController alloc] initWithNibName:@"SitView" bundle:[NSBundle mainBundle]];
            break;

        case 4:
            viewController = [[TimerViewController alloc] initWithNibName:@"TimerView" bundle:[NSBundle mainBundle]];
            break;
    }

    if (viewController != nil) {
        [self.navigationController pushViewController:viewController animated:YES];
        [viewController release];
    }
}