简体   繁体   English

Objective-C:如何从通用应用程序中的AppDelegate移出?

[英]objective-c : How to move from AppDelegate in Universal app?

I am developing a Universal app where I have 我正在开发通用应用程序

imageTracker_iPhone.xib
imageTracker_iPad.xib
imageTracker.h
imageTracker.m

I want to move from AppDelegate_iPhone to imageTracker. 我想从AppDelegate_iPhone移到imageTracker。 I am doing this in didFinishLaunchingWithOptions but its not working before this code I was using 我在didFinishLaunchingWithOptions这样做,但是在我使用此代码之前它不起作用

imageTracker *vRDi = [[imageTracker alloc] initWithNibName:@"imageTracker_iPhone" bundle:nil];
        [self.view addSubview:vRDi.view]; 

but it gave error request for member 'view' in something not a structure or union . 但是它给不是结构或联合的成员“视图”提供了错误请求 Even if code is like 即使代码像

[window addSubview:vRDi.view];

now The function is like below and its not working. 现在该功能如下所示,并且不起作用。 I want to move from AppDeligate to imageTracker. 我想从AppDeligate转到imageTracker。 please help 请帮忙

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {            

    [window addSubview:imageTracker.view];    
    [self.window makeKeyAndVisible];

    return YES;    
}

In this case It does not move to imageTracker_iPhone because did not tell any where to move to this file, so want to know that HOw to tell that which file to move either imageTracker_iPhone or imageTracker_iPad. 在这种情况下,它不会移动到imageTracker_iPhone,因为它没有告诉任何要移至该文件的位置,因此想知道如何知道将哪个文件移动到imageTracker_iPhone或imageTracker_iPad。

You probably want to set the delegate window's rootViewController to make your first controller active. 您可能需要设置委托窗口的rootViewController来激活您的第一个控制器。 (If you create a new test app from a single controller, non-storyboard template, you can see the kind of code that's needed in didFinishLaunchingWithOptions:.) (如果您从单个控制器(非故事板模板)创建新的测试应用,则可以在didFinishLaunchingWithOptions:中看到所需的代码类型。)

Edit: Actually, it's even easier than that. 编辑:实际上,它甚至比这更容易。 If you specify a universal app when creating a single view controller project, it creates the exact code to test which kind of device and load the matching .xib file. 如果在创建单个视图控制器项目时指定通用应用程序,它将创建确切的代码以测试哪种设备并加载匹配的.xib文件。 (Xcode 4.2, at least.) (至少Xcode 4.2。)

your code should be something like this 您的代码应该是这样的

imageTracker *vRDi;
Bool isiPhone = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;
if(isiPhone)
  vRDi = [[imageTracker alloc] initWithNibName:@"imageTracker_iPhone";
else
  vRDi = [[imageTracker alloc] initWithNibName:@"imageTracker_iPad";

and make sure that your connect view outlet in both xib's and the file owner is "imageTracker" Class. 并确保您在xib和文件所有者中的connect view插座均为“ imageTracker”类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从AppDelegate调用方法 - Objective-C - Call a method from AppDelegate - Objective-C Objective-c:AppDelegate NSString - Objective-c: AppDelegate NSString 从AppDelegate Objective-C IOS调用someClass内部的方法 - calling a method inside someClass from AppDelegate Objective-C IOS 我正在学习的“ Objective-C”中有多少是通用的Objective-C,而不是Apple的框架? - How much of the “Objective-C” I'm learning is universal Objective-C, and not Apple's frameworks? 如何用手指在iphone中移动视图Objective-c - how to move view with my finger in iphone Objective-c 如何从Javascript调用Objective-C? - How to call Objective-C from Javascript? 您可以将Objective-C iPhone应用程序和HTML5(PhoneGap)iPad应用程序捆绑在一起以制作一个通用应用程序吗? - Can you bundle an Objective-C iPhone app and an HTML5 (PhoneGap) iPad app to make one universal app? 通过本机iOS Objective-C应用程序与Python或Java通信吗? - Communicate with Python or Java from native iOS Objective-C app? 如何在Objective-C iPhone应用程序上从SQLite数据库发布和获取数据? - How to post and get data from SQLite database on objective-c iphone app? 如何在Objective-C中关闭iPad应用程序? - How can I close an iPad app in Objective-C?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM