【问题标题】:UIContoller interaction problem in navigation based iPhone Application基于导航的 iPhone 应用程序中的 UIContoller 交互问题
【发布时间】:2011-01-21 06:03:53
【问题描述】:

我在 Xcode 中创建了一个基于 Windows 的应用程序。我将 UIViewContoller 作为子视图推送到导航堆栈中。但问题是我无法与子视图上的控件进行交互。我是 iPhone 开发的新手。所以我不知道如何把事情做好。请在这方面帮助我。提前致谢:)

这是我在导航视图控制器中推送子视图的方式

if(self.userViewController == nil)
{
    UIViewController *vc = [[UIViewController alloc]    initWithNibName:@"UserViewController" bundle:nil];
    self.userViewController =vc;
    [vc release];
}

userViewController.title = [NSString stringWithFormat:@"Edit User"];
ShoppingListAppDelegate *delegate = [[ UIApplication sharedApplication] delegate];
[delegate.navController pushViewController:userViewController animated:YES];

【问题讨论】:

    标签: objective-c cocoa-touch xcode uiviewcontroller uinavigationcontroller


    【解决方案1】:

    首先,阅读 Apple iOS 文档中提供的View Controller Programming Guide。仔细阅读并遵循示例将为学习 iOS 和视图控制器基础知识打下坚实的基础。

    话虽如此,将视图控制器推送到导航控制器堆栈的正确方法是:

    在 .h 文件中

    @interface YourViewController : UiViewController {
        UINavigationController *navigationController;
    }
    
    @property(nonatomic, retain) IBOutlet UINavigationController *navigationController;
    

    在 .m 文件中

    @synthesize navigationController;

    在您要推送新视图的函数中

    UserViewController *myView = [[UserViewController alloc] initWithNibName:@"UserViewController" bundle:nil];
    [navigationController pushViewController:myView animated:YES];
    [myView release];
    

    【讨论】:

    • 就在导航控制器上推送 viewcontroller 而言,他的代码没有任何问题......相反,您的代码有问题,因为不需要在 YourViewController 中使用 UINavigationController,因为应用程序委托已经有一个。 .
    【解决方案2】:

    尝试将所有控件以及userViewController的userInteractionEnabled属性设置为true...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 2010-11-02
      • 1970-01-01
      相关资源
      最近更新 更多