我的问题是样本...但是我仍然不知道为什么我的观点不会推动其他视图...

首先,我在nsmutablearray中添加了许多视图

static NSString *titleKey = @"title";
static NSString *viewControllerKey = @"viewController";

- (void)viewDidAppear:(BOOL)animated {
    self.menuList = [NSMutableArray array];

    FirstView *firstView = [[FirstView alloc]initWithNibName:nil bundle:nil];
    [self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                              NSLocalizedString(@"FirstView", @""), titleKey,
                              firstView, viewControllerKey,
                              nil]];
    [FirstView release];


    SecondView *secondView = [[SecondView alloc]initWithNibName:nil bundle:nil];
    [self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                              NSLocalizedString(@"SecondView", @""), titleKey,
                              secondView, viewControllerKey,
                              nil]];
    [SecondView release];

好的...这是我在数组中添加viewController的方式...

当我按表视图中的单元格时,我想要的是我要显示的视图

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *targetViewController = [[self.menuList objectAtIndex: indexPath.row] objectForKey:viewControllerKey];
    targetViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [[self navigationController] pushViewController:targetViewController animated:YES];
}

按下牢房后,什么都没有发生

首先,我想可能是我没有正确设置数组

但是当我记录数组时

它确实有东西...

这是结果:

Log message: MENU LIST (
        {
        title = "FirstView";
        viewController = "<Firstview: 0x5822500>";
    },
        {
        title = "SecondView";
        viewController = "<SecondView: 0x5822870>";
    }
)

我不知道该程序为什么不起作用……

有人有任何想法吗???

这只是一件如此简单的事情,仍然在这里呆了3个小时。

非常感谢 :)

有帮助吗?

解决方案

首先,您需要检查 targetViewController 查看它是否给您正确的ViewController。如果是正确的,则

您真的应该检查 self.navigationController 确保不是的价值 nil

我怀疑第二件事是问题。

其他提示

好吧,我不得不说,布拉沃,这是一个艰巨的问题。

我可以肯定的是,我的答案会有所帮助,但只会听到我的声音。

当您使用

UIViewController *targetViewController = [[self.menuList objectAtIndex: indexPath.row] objectForKey:viewControllerKey];

您正在向UiviewController分配一类类型的FirstView或第二视图,这是我的问题。

但是,这是正确的,因为父母可以代替子类(假设两个类已将UiviewController分类)。

因此,您可以将一个断点放在

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

在控件到达函数末端之前,将光标放在targetViewController上,并检查其内容是什么。

如果它具有第一视图或第二视图,则将向您显示第一视图的变量类型,而第二视图是。

为了成功地进行推动操作,您需要使用root View Controller(root View Controller = FirstView->我希望这是UiviewController)在应用程序委托中创建Uinavigation Controller。

执行此操作之后,在FirstView中您可以致电

[[self navigationController] pushViewController:targetViewController animated:YES];

为了在堆栈上推动另一个UiviewController。

UinavigationController类实现了管理层次内容导航的专用视图控制器。该课程不打算子类。相反,您在希望应用程序的用户界面反映内容的层次结构的情况下使用它的实例。该导航接口使您有可能有效地显示您的数据,并使用户更容易导航该内容。

这是指向UinavigationController文档的官方链接,它们很有用。链接到uinavigation controller文档

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top