Tuesday, May 31, 2011

Build iOS Universal App without nib/xib

I just upgraded my universal app, iDiff, with a few features. Since I draw and layout everything by hand, it is a waste to keep the appDegelate_iPhone, appDelegate_iPad, and their xibs file, MainWindow_iPhone.xib, MainWindow_iPad.xib. Here is my note about this modification.

1. Delete all files in iPhone and iPad folder.
Those folders contain .h and .m file for iDiffAppDelegate_iPhone, iDiffAppDelegate_iPad, and MainWindow_iPhone.xib, MainWindow_iPad.xib.

2. Delete "Main nib file base name" property in project target setting.
There are two of them, Main nib file base name for iphone, MainWindow_iPhone.xib, and Main nib file base name (iPad) for iPad, MainWindow_iPad.xib.

3. Handle _window variable by ourself.
Delete the IBOutlet declaration for _window variable.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    self.window = [[[UIWindow alloc] initWithFrame: screenBounds] autorelease];

4. Tell main to load iDiffAppDelegate.
int main(int argc, char *argv[])
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"iDiffAppDelegate");
    [pool release];
    return retVal;

5. layout according to different device type

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            textHeight = 250;
            margin = 40;
        }else {
            textHeight = 100;
            margin = 10;

1 comment:

ali said...

plz help me
i am using spring mvc and json and jquery
when i send
in controler @Controller
public class UserController {
public @ResponseBody Boolean save(@ModelAttribute("user") User user, BindingResult result,SessionStatus status){
//do action
//problem here
//user.firstName is not علی
after map to model
unicode is not true
i set all utf8