Info light button Placement and transition - xcode

In the apps that i have seen, info light buttons are all in the navigation bar and when touched, the transition to a new view is a horizontal flip. Is it okay if i make an application that does not have the info light button in the navigation bar and when touched, uses the push animation to transfer the user to a new view? If not, could someone tell me how to code for the horizontal flip because when i choose Modal and flip and connect to a view, nothing happens when pressed (but works if if i choose push instead of modal.
Thanks

You can do what ever you want. There is no guideline for what kind of button should cause what kind of view change.
Here's a couple of examples of how to change view controllers:
//if you are using xibs use this line
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"myXib" bundle:[NSBundle mainBundle]];
//if you are using storyboards use this line
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"myViewControllersID"];
[controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
//this sets the modal transition style
//to present the controller modally use this
[self presentViewController:controller animated:YES completion:nil];
//or if you are pushing to this controller using a navigation controller use this
[self.navigationController pushViewController:controller animated:YES];

Related

NSPopover switch view

I have a popover menulet and it's contentViewController is some NSViewController. Everything fine here. The problem that I have is that I really don't understand how to change the View. I wanna load another view, and this is what I tried:
popover = [[NextViewController alloc]initWithNibName:#"NextViewController" bundle:nil];
[self.view addSubview:[popover view]];
And this works, new view is shown - but if I click on any button on that view I get error: unrecognized selector sent to instance. Why am I getting this error? Why this new view is not responding?
Please help me understand what I need to do, how to change the view on NSPopover?
I've managed to solve my problem, It turn out to be quite easy:
[self.view setSubviews:[NSArray array]]; //remove all previous subviews
[self.view addSubview:[popover view]];

UIImageView shifted when I click my back button

I've got a small project with two UIImageView-based nib files.
When the main view loads, it looks correct.
To switch between views, I'm using code like this (for example, this is to go to second view)
-(IBAction) secondClicked:(id)sender {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:main animated:NO];
[second release];
}
When the new view is shown, it's shifted sideways about 10% of screen. Using similar code to go back to main results in the main view being shown similarly offset.
I'm in landscape mode, if that makes a difference.
How can I display the views so they're correctly aligned?
Ok it makes sense now that I looked more carefully. Why are you presening a view controller modally when you wish to go back? How did you showed this viewController initially? If it was through a navigation controller you should pop the view
[self.navigationController popViewControllerAnimated:YES];
If it was presented modally you should just dismiss it!
[self dismissViewControllerAnimated:YES];

When a view is dismissed, the presenting view throws EXC_BAD_ACCESS

I'm converting my iPhone app to an iPad version, creating new XIBs for the iPad and rigging them to the existing objective C classes using the ~ipad XIB name.
In the iPhone version, I use the navigation controller to step backwards to the app. This should work just fine in the iPad too, but while the navigation controller does appear, it doesnt respond. In fact its invisible to any interaction, if theres a map behind the navigation controller and you double click back, you just zoom on the map where you clicked.
So I'm including a button in the iPad view which should do the same thing. On press I call a
[[self navigationController] popViewControllerAnimated: YES];
When I call this I get the EXC_BAD_ACCESS. I've gone in to the spooky zombie mode which gives me this
*** -[UIWindowLayer superlayer]: message sent to deallocated instance 0x83bb9f0
Ive determined that 0x83bb9f0 is the presenting layers self.view.layer
I'm using ARC to handle my allocations and deallocs.
THE QUESTION IS: How can I prevent self.view.layer from deallocing? or how can I allocate it again at the proper time so that I dont get this error?
I can provide more code if needed. Thanks so much!!
Edit: Heres where the main page (landing page) is created, and the nav controller
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
landingPage *LandingPage = [[landingPage alloc] initWithNibName:#"landingPage" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:LandingPage];
self.window.rootViewController = self.navigationController;
// [self.navigationController pushViewController:LandingPage animated:YES];
[self.window makeKeyAndVisible];
return YES;
Then here is where the inner view is called:
mapView *MapView = nil;
MapView =[[mapView alloc] initWithNibName:#"mapView" bundle:nil];
[self.navigationController pushViewController:MapView animated:YES];
So I got it!
The XIBs I was creating for the iPad version were windows instead of views. I recreated all of these as views and rigged it up and it worked just fine!

Hide/Unhide UINavigationbar when the screen is tapped

I'm very new with iOS Development and I have just created one of my first apps, in my .xib file I have a UINavigationBar that I want to hide/show when a part of the screen is tapped by the user (like in the Photo app). I've found some snippets online but I don't know where and how to use those.
I'd appreciate a lot if somebody could give me detailed informations about how to do this.
Add this toggle method anywhere in your UIViewController. This hides on first tap and shows again in second tap.
- (void)toggleNavBar:(UITapGestureRecognizer *)gesture {
BOOL barsHidden = self.navigationController.navigationBar.hidden;
[self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
}
If there is no navigation controller, link the navigation bar with an IBOutlet and replace with
- (void)toggleNavBar:(UITapGestureRecognizer *)gesture {
BOOL barsHidden = self.navBar.hidden;
self.navBar.hidden = !barsHidden;
}
Then add the following in the method -(void)viewDidLoad {}
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(toggleNavBar:)];
[self.view addGestureRecognizer:gesture];
[gesture release];
If the view where you are going to tap is a UIWebViewController, you have to add the protocol to the view controller and set it as delegate gesture.delegate = self; then add the following:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
This is needed because the UIWebViewController already implements its own gesture recognizers.
Ultimately, you want to send the -setHidden: message to your navigation bar. The easiest way to do this is to make an Outlet and an Action in your in your view controller. Then, in your .xib file, connect the navigation bar to the outlet and some button (even a large, full screen one) to the action.
Outlets and Actions are basic techniques used over and over in iOS
(and Mac) programming, so if you don't understand them, best go read
up on them now. Every beginning iOS/Mac programming book covers this
topic as does Apple's own Getting Started guide (pay particular
attention to the Configuring the View section).
Inside your action, send a message to the outlet like so:
-(void)myButtonAction:(id)sender{
[[self myNavigationBarOutlet] setHidden:YES];
}
This will hide the navigation bar whenever your button is tapped.
(This assumes you have a UINavigationBar in your .xib like you say. These directions will be different if you're working with a UINavigationController that manages its own UINavigationBar)

ios4 - Load new view on clicking a button

I am currently using XCode 3.2.3 and iOS4. I'm working on an app that simply starts with one screen and on a button click moves to the next.
I have gone thorugh the ViewController programming guide and a post here.
What I am doing is very similar to whats happening on the post. So let me explain the steps, I followed:
In IB, drag and drop, a View from the library into the editor. I renamed the new UIView to myView.
In my AppControllerDelegate, I added the new view "myView" as a property of the view controller (File's Owner). I synthesized it as well in the implementation.
Now, in the implementation of the ViewController, within the button pressed action handler, I wrote the following lines of code:
[self.view addSubView: myView];
On clicking the button however, I do not see a new screen or my new view. However if I do this, I get a new screen or new view:
UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame];
[self.view addSubView: anotherView];
I do know that the best way is to do it with separate NIBs for each UIView. However, I am new to iPhone development and have not explored that path as yet.
My question: What am I missing upto step 3?
One way you could be able to do it is by trying it this way
myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle: [NSBundle mainBundle]];
[self.view addSubview: myView.view];
Try that and see if it is working.. if yours is a view based project then instead of [self.view addSubview: myView.view], just give [self.view addSubview : myView];

Resources