Reputation: 11782
i am totally new to iphone
and i am trying to create a universal app.
Now I am creating an empty application. According to all tutorials , by checking universal
option it should auto create appdelegates
for both iphone and ipad.
But all i can see is only one appdelegate
. Kindly tell me how can i create both.
Best Regards
Upvotes: 0
Views: 1572
Reputation: 7226
Brayden is correct in answering that you almost never need multiple app delegates. All the delegate usually does is handle the moments when the application launches, suspends or terminates. Back in the days when iPhones ran iOS 4.0, and iPads ran iOS 3.2, you might need very different code in the delegate because only iOS 4.0 supported multitasking. Those days are long gone, and your delegate should probably act the same on all devices.
Yes, you sometimes do reach a point where your program must behave differently on iPhone and iPad. Check the idiom at that time and no earlier. Otherwise you're just duplicating code to no purpose.
My most recent app contains almost no special checks for iPhone or iPad. It doesn't even use different XIBs. Instead, my custom views implement layoutSubviews
to fill the space available.
That said, once you understand app delegates, maybe you will find a situation where you need them to be different. If you are absolutely certain that your iPhone and iPad behavior will be so wildly divergent, you will need to:
AppDelegate
class)main.m
, send the class name of your new delegate to UIApplicationMain
depending on the idiom.See this answer to "Can I create App Delegate file in my project?" to see the changes to main.m
.
Upvotes: 3
Reputation: 1795
You really should only be using one AppDelegate for a Universal application. You can use this to share common things that you'll do in there. What exactly do you need multiple AppDelegates for? If you need to do something specific to a device type (i.e. - iPhone or iPad) then you can do a ternary expression like below:
(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? NSLog(@"iPad") : NSLog(@"iPhone");
Upvotes: 3