在表格视图中显示模态视图控制器

3

大家好。

我在表视图控制器中有以下代码:

    else if (editingStyle == UITableViewCellEditingStyleInsert) {


        if([[UIScreen mainScreen] bounds].size.height == 568)
        {
            citySearch = [[CitySearch alloc] initWithNibName:@"CitySearchIphone5" bundle:nil];

        }
        else
        {
            citySearch = [[CitySearch alloc] initWithNibName:@"CitySearch" bundle:nil];
        }
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:citySearch];
        [self presentModalViewController:navController animated:YES];

当我呈现视图时,出现了超出边界的情况,Xcode会显示以下内容:

不建议在分离的视图控制器上呈现视图控制器

如何解决这个问题?


你在使用UISplitViewController中的表视图吗?当我使用分割视图的主视图来呈现模态视图控制器时,我也收到了同样的消息。使用分割视图来呈现它可以解决这个问题。 - Christoph
2个回答

1

presentModalViewController:animated:iOS 6.0 中已经被弃用。请使用 presentViewController:animated:completion: 替代。

[self presentViewController:navController animated:YES completion:nil];

苹果文档


我已经这样做了,但什么都没改变。 - Pavel
你是否正在使用故事板?请检查 navControllercitySearch 是否回流到你的表视图控制器。 - Nikhil Patel
然后在 application:didFinishLaunchingWithOptions: 中检查是否设置了 rootViewController - Nikhil Patel
那是因为您正在展示一个新的 UINavigationController,默认情况下它包含了一个在顶部的 UINavigationBar - Nikhil Patel
我解决了。但是还有一个问题:当我关闭模态视图时,父视图会向左上方移动。 - Pavel
显示剩余3条评论

-1
 MACommentsViewController *obj_AboutVC;
 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
 {
    if (IS_IPHONE_5)
    {
        obj_AboutVC = [[MACommentsViewController alloc]         initWithNibName:@"MACommentsViewController" bundle:nil];
    }
    else
    {
        obj_AboutVC = [[MACommentsViewController alloc] initWithNibName:@"MACommentsViewController_iPhone4" bundle:nil];
    }
}

[self presentViewController:obj_AboutVC animated:YES completion:nil];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接