UIImageView shifted when I click my back button - xcode

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];

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]];

Info light button Placement and transition

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];

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];

How to create a window like the e-mail app that pops up

I want to create a window that pops up like in the email app when you hit New Email.
Does anyone has a good tutorial or sample code of how to do this?
This is the screen I want:
Basically it looks like a view controller shown modally with modalPresentationStyle set to UIModalPresentationPageSheet:
SomeViewController *vc = [[SomeViewController alloc]
initWithNibName:#"SomeViewController" bundle:nil];
vc.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:vc animated:YES];
[vc release];
On the view controller, at the top is a UIToolbar and the content underneath can be shown in several ways including a UITableView.
In portrait, the modal view will be the full width of the screen.
It's a modal view controller with style as pagesheet.
You have to present whatever you want as a modal view controller after setting it's modal style.

UINavigationController back button issue

My Application have navigation controller and table views. When the back button is clicked and the view is popped out from controller stack, i noticed that the table events are not executed (eg: cellForRowIndexPath). Is there anyway that these events are execueted when view is popped out.
This is the code i use for pushing the view into controller stack.
MyViewController *obj = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
Regards
Sandy
You can use the ViewWillAppear and ViewWillDisappear methods.
what you want to do is put a call to
[theTable reloadData];
which initiates all of the calls that you wanted.
This call should be placed where you want the table to reload - either on appear or disappear.
Good Luck !

Resources