Skip to main content

Posts

Showing posts with the label uiviewcontroller

Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?

I have an application in which I would like to support multiple orientations. I have two .xib files that I want to use, myViewController.xib and myViewControllerLandscape.xib. myViewController.xib exists in project/Resources and myViewControllerLandscape.xib exists in the root project directory. What I want to do is use a separate NIB (myViewControllerLandscape.xib) for my rotations. I try detecting rotation in viewDidLoad like this: if((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)) { NSLog(@"Landscape detected!"); [self initWithNibName:@"myViewControllerLandscape" bundle:nil]; } But I can see in gdb that this isn't executed when the app is started with the device in landscape. The NSLog message doesn't fire. Why is this? What have I done wrong? Also, if I explicitly put the initWithNibName function call in the viewDidLoad method, that nib is not loaded,

Three UIViewControllers on the same window

I want to develop the following application: on top I have a navigation bar, in the middle a TableViewController and on the bottom I have a custom control that is actually a slider (when I move the slider I want to present another TableViewController - but my navigation bar remains the same). And when I select a cell in the TableView I want to push a new ViewController (so I will change my navigation bar) and I will also dismiss my custom control. I have attached a picture of the prototype of my application.How would you suggest that I should implement this? My custom control is designed using IB so I think I should use the old way, using .xib files, not the Storyboard.

Adding UIView subclass programmatically not drawing itself

I don't understand how this works. If I draw a UIView object to my UIViewController .xib file, then my UIView redraws itself. If I add it to the subView like CustomView : UIView in UIViewController's viewDidLoad CustomView *v = [[CustomView alloc] initWithFrame:self.view.frame]; [self.view addSubview:v]; The CustomView not draw itself. I then tried to do [self.view setNeedsDisplay]; and I still get nothing. Just a white background (different than the black background I was getting before), but none of my drawing. How does it work when you add a UIView programmatically? thanks.

UIviewcontroller size issue in IPhone?

I have a UIviewcontroller in a navigation based project, to which i am pushing some views as a result of some button action. When I first load this view, its size is showing (0,0,320,416) in the viewwillappear method. But, if you run it again, its size is showing (0,0,320,460) in the same viewwillappear method. My view is seems to be resizing when you load it again. Due to that I have so many problems in the pushed view. Can anybody help me please?

ViewController gets deallocated which leads to crash

I have a view in my storyboard which I assigned an identifier called "MainView". However if I add its view to the subview, everything that follows produces a crash (e.g. pressing a button) MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainView"]; [self.view addSubview:mvc.view]; This is the action triggered by the button : (MainViewController.h) -(IBAction)showUsername:(id)sender{ [testLabel setText:@"username"]; } and the crash log : -[MainViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x44e0810 I use ARC.

Switching Between View Controllers Efficiently

In order to switch between views in my iOS app, I have been using Modal View Controllers. It works fine, but is this bad coding practice? Will it be detrimental to the memory usage of my app? In response to comments asking for more information, the views I am switching between are normal informational views. I am using three views to navigate through my app: Main View: Has buttons to navigate to specific informational views Info View: Has buttons to navigate to specific web pages for information Web View: Displays information through a UIWebview I have an improvised navigation bar at the top for navigating "back" and "home" do the main page. Overall, this is a web app with structure provided with menus in other views. I don't want to reveal what it does specifically (it's my idea), however this should be enough information to work with. I am currently switching between views like this: newViewController *newView = [[newViewController al

dismissModalViewControllerAnimated doesn"t return

If I push a view onto the Navcontroller it works great and I can return from it either with code or using the Nav Controller back button. Then I change it to present the view modally. The preset works but I cant get it to return and dismiss the modal view. This works... main view Tools *screen = [[Tools alloc] initWithNibName:@"Tools" bundle:[NSBundle mainBundle]]; [mainNavController pushViewController:screen animated:YES]; [screen release]; One the modal view: - (IBAction)btnCancel:(id)sender { [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES]; } But then I change it to modal like this on the modal view it does not go back to the main view. Tools *screen = [[Tools alloc] initWithNibName:@"Tools" bundle:[NSBundle mainBundle]]; [mainNavController presentModalViewController:screen animated:YES]; [screen release]; On the modal view: - (IBAction)btnCancel:(id)sender { [