I'm working on an iPad app (actually, converting a iPhone app into iPad app). Since I can put two "Iphone screens" on one "iPad screen" (just regarding the space), I have my iPad view 50% occupied by my original view (loaded through my main controller).
(so far so good)
Now, on the remaining 50% of the iPad view, I want to include another View (for which I have a controller and a view, iphone-sized). I tried to add a "View" component, but how do I load another controller into it ? is that even possible ?
MainViewController loading MyView1.xib
I want to load, in the "View" component, MySecondaryController, loading MyView2.xib
http://imageshack.us/photo/my-images/835/d8fs.png/
Thanks
you can do it something like below...write below code in function which is in Mainviewcontroller(for example on some button tap)
yoursecondviewcontroller *objDate = [[yoursecondviewcontroller alloc] initWithNibName:#"yoursecondviewcontroller" bundle:nil];
objDate.delegate = self;
UIPopoverController *datePopOver = [[UIPopoverController alloc] initWithContentViewController:objDate];
datePopOver.delegate = self;
[datePopOver setPopoverContentSize:CGSizeMake(320,393)];//give any size you want.
[datePopOver presentPopoverFromRect:CGRectMake(50,700, 320, 393) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];//give size and origin whatever you want in FromRect .....
You can also define UIPopoverController object in .h file....
and don't forget to set delegate of UIPopoverController that is UIPopoverControllerDelegate
Let me know it is working or not!!!
Happy Coding!!!!
Related
I built an iPhone app "using xib" with 5-6 screens. Now I want to auto-resize the display for iPad. I am using xcode 4.6.
Do I have to rebuild the entire code using storyboards? It will be a very tedious work. Is there any solution for this?
You'll need to create only new xib files for iPad and name them as ViewController_iPhone.xib and ViewController_iPad.xib and when switching your views, just put a simple condition
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPad" bundle:nil];
} else {
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPhone" bundle:nil];
}
use autolayout and everything will be done automatically
if not autolayout, then making 2 xib will be a better option. Make ipad size xib with the same name and put ~ipad after classname.
Like if you xib name is myClass.xib and create other one like myClass~ipad.xib.
I have a problem that began after I changed my project to a universal application and switched to the updated version of Xcode.
At the moment, my application has a navigation bar with a controller that has a button. The button will pop up a UIPopoverController when the user clicks it. Everything was fine here. Now I try to interact with the list inside UIPopoverController and there is no reaction at all in the list. In addition, when I try to dismiss the popover controller by tapping outside the popover controller, the popup does dismiss at all as well as I can even interact the controls behind the popover controller.
It worked fine before I updated Xcode to the latest IOS. Inside the code I have changed was having the xib file to have the window view and inside the app delegate file I initialized that xib file.
This is shown the code below.
TViewController* controller = [[TController alloc] initWithNibName:#"MainViewController_IPad" bundle:NULL];
[controller.navigationController setNavigationBarHidden:TRUE animated:TRUE];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window setRootViewController:controller];
[self.window makeKeyAndVisible];
//((TopicShowViewController*)self.window.rootViewController).navigationController.navigationBarHidden = true;
self.navigationController = ((TopicShowViewController*)self.window.rootViewController).navigationController;
self.navigationController.navigationBarHidden = true;
[controller release];
The code above, I have to create the window object but the TViewController itself has a window object already. If i run this without either window object in the xib file or explicit initialized the window object from code above, the TViewController won't display as expected.
I have no idea what is going wrong here... Sorry the description may be too long to understand but please help.
A universal application is an app designed to run on both an iPhone and an iPad. However, the UIPopoverController is not supported on the iPhone. If you try open a popover on an iPhone your app will throw an exception.
I am modifying my iphone app to make it backward compatible with iOS 3.1.3. I allow the user to load images from the photo library. I present the image picker with the following code:
UIImagePickerController* content = [[UIImagePickerController alloc] init];
content.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
content.delegate = self;
[self presentModalViewController:content animated:YES];
[content release];
This works correctly on ios 4.0+. However, on ios 3.1.3, the image picker never appears, and I get the following warning:
Can't perform full-screen transition. The fromViewController's view must be
within a view that occupies the full screen.
The fromViewController in this case is the visible view controller within a navigation controller. The navigation controller is set up in the appDelegate didFinishLaunchingWithOptions using the following code segment:
MyViewController* root = [[MyViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:root];
aNavigationController.delegate = self;
[window addSubview:aNavigationController.view];
Prior to attempting to load the image picker, another view controller is presented in the navigation controller. Therefore, at the time the image picker is loaded, two view controllers are in the navigation stack.
Based on another post, I have tried using the root view controller and the navigation controller as the fromViewController (the controller presenting the image picker). The behavior is the same.
I'm wondering if the problem has anything to do with the fact that the navigation controller's modalPresentationStyle cannot be set in iOS 3.1.3. For iOS 3.2+, I set the presentation style to UIModalPresentationFullScreen. I believe this is the default for previous iOS's. However, I'm suspicious simply because the warning I'm getting concerns full-screen views.
Can anyone provide any other suggestions? I have not been able to find any Apple documentation that addresses changes to UIImagePicker or UINavigationController from ios 3.x to 4.0.
Thanks in advance!
What I usually do when the view controller is inside a navigation controller is:
imagePicker = [[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
[self.navigationController presentModalViewController:imagePicker animated:YES];
Hope it works for you!
I have an iPhone application (app1) which has to be integrated as a sub-application on another universal iOS app (app2).
For various reasons I don't want to create an iPad interface for my iPhone app1, I just want that all the views will be shown with iPhone dimensions (at the center of the screen) also when the main app2 is executed on an iPad. On app1 I do not support landscape orientation, only portrait.
Is this somehow possible to realize?
Thank you in advance.
This is the code!
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:yourViewController];
[popoverController setPopoverContentSize:CGSizeMake(320, 480)];
And to show the popoverController in the middle of the iPad screen
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad){
[popOverController presentPopoverFromRect:CGRectMake(380, 450, 1, 1) inView:self.view permittedArrowDirections:0 animated:YES];
}
To maintain always the same size of your UIPopoverController do not forget to set the contentSizeForViewInPopover in each view (do this inside the viewWillAppear:)
- (void)viewWillAppear:(BOOL)animated{
[self setContentSizeForViewInPopover:CGSizeMake(320, 480)];
}
Yes - you can do this. Assuming you have built your original application using UIViewControllers, the iPad has a special kind of class called a UIPopoverController where you can spawn a UIViewController onto the screen of the iPad at a given size.
To embed an iPhone app in a iPad app, set the root UIViewController of your iPhone App to the View Controller in the Popover Controller, set the size of the popover to 320x640 and spawn it by calling the presentPopover function.
I hope this helps!
N
I am a beginner, and I have an iPhone app.
I want to convert iPhone app to iPad app.
I want to increase the size of all control, images and views according to iPad dimensions programmatically as I have no controls in XIB but in fact they are programmatically made.
I don't want to change the dimensions manually at every place because it is too much of a cumbersome work.
Is there any way I can do this in a better way?
The simple answer is NO.
You have to do it manually. There is no automatic system.
That is the correct answer.
if you have an absolutely trivial app - ie, with no images or controls or layouts! - you can of course just change it to an iPad app.
The questioner is asking specifically how to change all the images, layouts, and so on in a normal app. The answer is it must all be done completely manually. There is no automatic system for re-doing design or re-doing images in Photoshop, etc.
Note that similarly if you want to do both portrait and landscape layouts of an app, you or your designers have to of course simply design both layouts. There's no, say, "artificial intelligence" system that automatically does art direction for the app! You simply have to manually design both layouts and manually build in Photoshop all necessary images for each situation. The same applies to iPad v. iPhone.
(Note that sometimes you will have to do four totally different layouts, and sets of graphics .. for the phone/pad and portrait/landscape.)
This is exactly why iPad apps are sometimes labelled "HD" in the app store - they are of course totally different.
In Xcode, click on your project on the "Groups & Files" sidebar. Press command-I. Search for Targeted Device Family and change it from iPhone to iPad. Then it will compile and run on an iPad but the UI might look a bit funky.
What I did after that was open the xib I used for my iPhone app's FlipSide view (the one that looks funky on the iPad) go to File->Create iPad version and save it as FlipSideiPad.
Then when I load the view controller, I used the following if statement to tell my program to load the iPhone interface if the device is an iPhone or to load the iPad interface if the device is an not an iPhone.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
else
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"iPadFlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
I hope that helps.
You need to resize the view manually...there is no such single methods for converting iphone app to ipad