Trouble with using popViewController flashing white during transition - uinavigationcontroller

I have been struggling with switching between views using the UINavigationalController. I have used this system many times without issue but in my new app it isn't working properly.
Here is the issue:
When i am pushing a new view controller i use the following code:
NewViewController *newVC = [[NewViewController alloc] initWithNib:#"NewView" bundle:nil];
[self.navigationController pushViewController:newVC animated:YES];
[newVC release];
The code I am using to return to the previous view inside of the newVC is:
[self.navigationController popViewControllerAnimated:YES];
I was reading that this could potentially be releasing the self.navigationController itself so I implemented this code:
UINavigationController *nc = [self navigationController];
[nc popViewControllerAnimated:YES];
What results is a smooth transition to the newVC with no white flash, but when returning to the original page the screen flashes white as if it is releasing the newVC before transitioning back to the original page. HOWEVER! When debugging I placed breakpoints on viewWillAppear of the original page and on the dealloc of the newVC and the viewWillAppear + transition with white flash all complete BEFORE the dealloc of the newVC is called.
If anyone could please help shine some light on this I would greatly appreciate it.
Thanks!
~Arash

This is an old post, but for those who may run into this issue in the future, I have solved it by setting the clipsToBounds property of the view of the ViewController to "TRUE"
-(void)viewDidLoad {
[super viewDidLoad];
self.view.clipsToBounds = YES;
}

Try changing the background colors of the various views on the navigation stack to different recognizable colors (including the main window). One of them might be showing for some reason, and if each one has a different color you can determine which one is the culprit pretty easily.

FWIW, this same issue happened for me in a Swift app. The root cause appeared to be that I was doing this:
self.navigationItem.rightBarButtonItem = nil
...to dynamically hide the button, where the UIBarButtonItem had an outlet in the current UIViewController.
I did not actually need an IBOutlet for that button, so I removed the outlet, and it worked.

Related

UIBarButtonItems shift position when UINavigationController is presented modally

I'm presenting a UINavigationController modally, from within an iOS app extension:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:nav animated:YES completion:nil];
When the navigation controller appears, its root view controller's UIBarButtonItems jump position:
I'm creating and adding the buttons in viewDidLoad. They are just standard bar button items:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(done)];
I'm not overriding viewDidAppear (which appears to be the point where the buttons jump).
Presenting this same navigation controller/root view controller from within my app, instead of the app extension, doesn't give me this same problem. Any ideas?
I'm hoping someone else finds a better way to do this, but my current solution is to create stand alone buttons and then use [[UIBarButtonItem alloc] initWithCustomView:] with the button. Not ideal, and the indention is still there, but the weird jump doesn't happen anymore.
If the indention bothers you, you could also set negative fixed spaces on the outsides of the buttons to shift them closer to the edges.
Here's an example including the spacer:
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
<other button config here, set targets, whatever>
[button sizeToFit];
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:button];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixedSpace setWidth:-8.0f];
self.navigationItem.leftBarButtonItems = #[fixedSpace, leftBarButton];
This only happens to me on my share extension, and I don't have any problems related to presenting from a detached controller or anything like that.
As #Stonz2 mentioned, this appears to be a characteristic of presenting a modal from a detached view controller. I was having the same problem and remedied it by re-organizing my app so that it wasn't presenting from a detached controller.
You'll know if you're presenting from a detached controller if you get the following error message:
Presenting view controllers on detached view controllers is discouraged
I was presenting from a detached viewController. I never got the warning. But I tried embedding that detached viewController in a NavigationController, and the problem went away.

How do I create a home button in the top right hand side of my UINavigationController

How do I create a home button in the top right hand side of my UINavigationControl. Please note that I have instantiated my UINavigationControl on my second UIviewController named: ViewControllerSecond. I want to be able to have the tradition "Home" icon, and when pressed to resign back to my first UIviewControler within the appDelegate named: ViewController.
I've got this far:
#property (nonatomic, weak) UIBarButtonItem *homeProperty;
UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:#"Home" style:UIBarButtonItemStylePlain target:self action:#selector(home)];
[self.navigationItem setLeftBarButtonItem:homeButton animated:NO];
But I cant link it with my first ViewController or replace the text with a home button image.
Many thanks
I also need the answer to this question as i couldn't find an answer to this question anywhere else.I would hav voteup'd this question if i had 15 repu :(
btw i want the selected items in my tableview to be posted on a new view controller when the "done" button on my top-right navigational bar gets clicked.I have also reached the same distance as the asker of this question.
Forgive me for posting my words in the answer section to this question as i can't post in comments to that question due to that 50 repu :(
EDIT:I think i found an answer,try this plz
Since you hav action:#selector(home) so your method name will be:
- (IBAction)home:(id)sender {
//statements to execute
}
You don't have to link this method with anything as you have already declared this method as selector while declaring that "home" button.Neglect the open linkage in front of your method.
http://prntscr.com/1tc0q9

MvvmCross UINavigationController customise navigationBar

Further to my experiences with MvvmCross, I've managed to build an app for iPhone which starts with a TabBarController. I can also successfully navigate within each tab to deeper levels. The problems start when I want to customise the navigationBar on the deeper levels - setting the backButton colours, etc. The code I use for navigation is the standard viewModel code -
this.RequestNavigate<InJourneyViewModel>();
…which works fine, but I can't do anything to the navigated-to view's navBar, other than set its title.
Any thoughts or advice appreciated!
I think it might help if you posted some more of your code that is failing.
My suspicion is that the problem is a more generic Cocoa, MonoTouch and/or backbarbutton problem.
I've just played with the ViewDidLoad code in MapView.cs in https://github.com/slodge/MvvmCross/tree/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch
At the end of this, I was able to add some bar button changes like:
var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
leftButton.TintColor = UIColor.Green;
NavigationItem.SetLeftBarButtonItem(leftButton, false);
NavigationItem.RightBarButtonItem.TintColor = UIColor.Red;
Which resulted in:
Alternatively, by placing code in the WelcomeView:
var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
leftButton.TintColor = UIColor.Green;
NavigationItem.BackBarButton = leftButton;
Then I succeed in achieving:
Alternatively, by using code like:
UIBarButtonItem.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = UIColor.Blue;
Then this enabled me to customise all the navigation bar buttons like:
At one point, I also managed to achieve:
... but sadly I've genuinely no idea which code combo gave me that! If your problem is with back buttons in particular, then I think you will need to dig around other questions and/or post some code and hope someone can help - there's lots of posts about how to do this, but I can't quite figure out what they all mean for MonoTouch - e.g. Separate title in NavigationBar and navigation buttons

popToViewControllerAnimated does not animate since ios5

as topic describes, calling popToRootViewControllerAnimated / popToViewControllerAnimated does not do any animation anymore.
the code I use, which works fine with 4.x, is simply
[self.navigationController popViewControllerAnimated:YES];
so nothing special here. I just noticed, that for all my apps, running on iOS5, pop-animations have been gone. push-animations however DO appear.
now i wonder what to search for, if there is the need to define the transition/style of that animation?
Any help welcome, thanks!
Okay, calling "[super viewWillAppear]" in "viewWillDisappear" is sort of ... my bad!
Was having the same problem. view transition animation for poptoRootViewControllerAnimated was working fine pre ios5.0 but not in ios5. Below is a brief description to fix it.
I had implemented a custom Tab bar in view A. When I transitioned to view B from A and then back, the view transition animation stopped working for B to A. Upon looking at the view loading methods in view A and all its sub-views, my customTabBar in view A had ViewDidAppear that was erroneously calling [super viewWillAppear] inside it. When I corrected it to [super viewDidAppear] , the pop animation started happening OK.
Looks like pre iOS 5, it did not matter but now it does and rightfully so.

viewDidAppear Not Firing in Tabbarcontroller>NavigationController>UITableView

I currently have a tab bar controller set up with a navigationcontroller on one of the tabs, then I have a UITableView nib set up for that Navigationcontrollers view. All of this has been set up through IB and I want to keep it that way. Kind of like this tutorial http://twilloapp.blogspot.com/2009/05/how-to-embed-navigation-controller.html
now the view loads perfectly when ViewDidLoad is called. But when I then load further views via code IE
MyApp_AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *nav = (UINavigationController *)delegate.controller.selectedViewController;
newViewController = [[newViewController alloc] initWithNibName:#"newView" bundle:nil];
[nav pushViewController:newViewController animated:YES];
//At this point the view works! and loads
If I try to go back with the navigation toolbar it goes back to my previous view fine
Now I need to refresh the tableview when I go back but calling viewDidAppear does not work.
I tried adding UINavigationDelegate to the same ViewController Class as the tableview and then calling - (void)navigationController:(UINavigationController *)navigationController didShowViewController:
But that did not work. I also tried adding the same delegate as the tab bar controller and adding the same navigationController didShowViewController: there but that also failed.
How do I get this table to refresh every time the view loads?
You should not have to call viewDidAppear from your code. Cocoa Touch should do that for you.
Call the table view's reloadData method to get it to refresh its contents.
Found I was missing the Delegate declaration in the Interface file. doh! also I tried that in lots of places it only ended up working when I added it to the NavigationControllers first view (my table view)

Resources