【问题标题】:Error occurred in appDelegate methodappDelegate 方法发生错误
【发布时间】:2012-10-25 18:36:06
【问题描述】:

当我运行样本信号时,appDelegate.m 文件中发生错误,中止

self.view.controller=root.view.controller 

请帮我在下面添加代码

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    /* bad signal occurred at this line */
    self.window.rootViewController=self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

谢谢

【问题讨论】:

    标签: iphone ios xcode uiimageview


    【解决方案1】:

    UIWindow rootViewController 属性在 iOS4 之前不存在。如果您尝试在装有 iOS 3 或更早版本的设备上运行此代码,它将崩溃。

    在您的 AppDelegate 中,您可以改用 addSubview。

    //self.window.rootViewController = self.viewController; // Only iOS >= 4 [self.window addSubview:self.viewController.view]; [self.window makeKeyAndVisible]; return YES;

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      self.view.controller = root.view.controller 的语法有点奇怪。我想你的意思是self.viewController = rootViewController?即便如此,这是不正确的。

      尝试类似 -

      self.viewController = [[YourViewController alloc]init];
      self.window.rootViewController = self.viewController;
      

      将 YourViewController 替换为控制器的类。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-10
        • 2018-04-12
        相关资源
        最近更新 更多