I have an app with a navigation controller that does a segue to another view controller and then checks for the presence of an object in viewDidLoad (that may or may not exist). It then updates the name of a barButtonItem if the object exists. The problem is I can see the button expanding to accommodate the new name as the segue occurs.
How can I make this button change before the view is loaded so this jumping button effect is not seen? Shouldn't changes made in viewDidLoad not be seen until after viewDidAppear?
Related
I'm trying to implement segueing from a tableview controller when the user taps the cell's accessory button.
I've searched on here and have some new things to try but I just wanted to ask whether in the storyboard you can actually create the segues from the accessory button, or whether you just need to create them from the tableviewcontroller.
It'll be within the accessoryButtonTappedForRowWithIndexPath that I'll want to act on the tap, but I see some answers on here say that you have to just go from the tableviewcontroller when creating your segues where as another answer said that the sender within prepare for segue would be set to the cell that contains your accessory view.
Whenever I try to ctrl drag from the accessory button in my prototype cell it just gets rid of the already existing on-selected segue I'd setup for that cell.
Just wanted to know for sure, what the best practice was before I started making all my detail accessory segues just go from the root TableViewController and passing through accessoryButtonTappedForRowWithIndexPath's indexPath (or it's row) as the sender to my prepareForSegue.
Cheers
Ok, after trying the suggestions I described in my original question I got the code all working how I wanted. I added segues from the root tableview controller and then performed them programatically within the accessoryButtonTappedForRowWithIndexPath delegate function.
I have a few Table View Controllers doing similar things in my navigation controller so I set about implementing this accessory button workflow in each of them. When i reached the last TVC in my nav controller hierarchy I didn't want selecting cells to go any further, so i changed the accessory type to just detail.
As I wasn't concerned at this stage to have the cell interaction sourced segues overwriting each other I just dragged a segue out from the prototype cell to the destination view controller. Upon doing so within the add segue popup I saw 2 options - Selection Segue and Accessory Action. I'm sure that when I first tried doing this I only had the single Selection Segue choice.
Regardless of whether this was my tired eyes missing it, or Xcode having a funny turn (as it seems to from time to time, being laggy at updated states of various files etc) I can now say in answer to my original question, all you have to do is setup your accessory action segue as required. You can have both selection segue and accessory action segues setup from the same prototype cell, and everything just works as you'd expect.
I've just updated my setup to work this way and all seems fine.
Cheers
At the bottom of the Detail View Controller of a Split View Controller, I have added a Toolbar in the Storyboard. I have added three Bar Button Items in this Toolbar. Each Bar Button Item is hooked to its IBOutlet in the private interface of the Details View Controller, and also hooked to its IBAction implementation in the same controller, for example:- (IBAction)shouldPresentView:(UIBarButtonItem *)sender
The main view contains:
A Webview.
A small rectancgle view at the bottom of the screen, below the webview, created and added programmatically, and containing various buttons. All the buttons stay operational.
When touching any of the Bar Button Items, the button is temporary highlighted, but none of the IBAction methods is triggered (a NSLog() statement in every method is never executed).
After searching and reading equivalent topics, I went through several solutions:
I added manually the Details View Controller as the delegate of the Toolbar in the View Did Load method of the Details View Controller.
I emptied the cache of the Derived Data of the Product.
I checked that every IBOutlet has an address and is not nil.
I tried to add an action SEL manually in the View Did Load method for every Bar Button Item.
I removed the rectangle bottom view to be sure that it was not interfering with the responder chain.
I added a Bar Button Item in the Navigation Bar to check if the same problem occurs: no, the Bar Button Item fires the IBAction method.
Any help would be appreciated.
Developing with iOS 7 SDK in Xcode 5.0.2
The issue was coming from a Tap Gesture that I added to the main view to collect touches on the web view. So the touch on the Bar Button Items was probably captured somewhere by the main view before reaching the UIButtonBarItem. I changed the target of the Tap Gesture to the web view – more logical – and the issue has been solved.
I'm doing a storyboard segue when tapping a navigation bar button item, from view controller A to view controller B, and it works fine with a push animation. But when I tap the back button (no custom code) the previous view (A) just pops into place without the sliding animation. The same happens when I do a [self.navigationController popViewControllerAnimated:YES], i.e. there's no animation. I've made sure that I'm only popping it once.
This has been tested in the simulator as well as on a device.
I suspect it has something to do with what happens when view controller B is being unloaded or something similar, but I can't put my finger on it. I am handling an ABRecordRef property in B, but I have tried to be careful to call CFRetain and CFRelease in the setter when appropriate. I'm doing calls to outlets in various setters and getters but again have been careful to only do it if the view is loaded in case that would cause the view to reload after being unloaded. No success.
Finally did a log in B's viewWillDisappear, and animated is set to false. Why's that?
I don't know what to do next, my segue has the "push" style in the storyboard.
I have an app I am working on that has a main screen with two buttons. One will take you to a view of a GPS (map) and then once there (new VC) it has options for setting that position or bringing up a list (tableview, another VC) of all locations already tagged.
At the list VC, if you click on the table cell, it will bring up the VC with the map. Problem is, this then adds the same VC bak on the stack. If a user clicks the Cancel button, they go back ones screen, then cancel goes back another screen, etc... until back to the main.
I know I can do the [self.navigationController popToRootViewControllerAnimated:YES]; to pop back to root but that is not always what I want.
Also, I know I can do: [[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
I guess what I am saying is I want to "reuse" the GPS map view so I can call it from other VC's, so that is why I didn't go with the "pass back" to calling VC. So, is there away to either when a button is pressed and is to present a new VC, can I dismiss the prior one after the new one is shown? This way, a dismiss of current VC would take me back to where I need to be.
I hope makes sense and also that this question doesn't fall into the "Not an actual question" category.
Any help or better suggestions is greatly appreciated. Thx
Geo...
If you want to jump back some number of levels in a navigation controller's VC stack, you'll probably want to use its popToViewController:animated: method. To figure out if a particular view controller is on that stack, look at the navigation controller's viewControllers property. Be careful, though, as this kind of jumping around is a rather nonstandard UI behavior (even though there's API for it) which might confuse your users.
Also, using navigation controllers and presenting modally aren't the only ways to manage multiple view controllers -- you can always set the window's rootViewController yourself (and animate the change with UIView animations), even wrapping up your custom transition type in a custom UIStoryboardSegue if you like.
You can put a delegate in the table view. So that when a cell is pressed the info is passed to the delegate method in the VC which will dismiss the table view and reloads itself with the new info. You will have to implement refresh method in that VC.
Hi there and thank you in advice for your help. I have a really strange problem while working with ViewControllers in Xcode4. First of all I have to say that I'm not using storyboards and I prefer to create any UI element programmatically. So I've set a UIButton and I want that, when pressed, it brings me to a new view controller. This is the code I'm using for a button:
-(void)settingsAndExportHandle:(UIButton *)buttonSender {
SettingsViewController* settingView = [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
settingView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:settingView animated:YES];
}
This buttons is initialized and allocated in the viewDidLoad method of the RootViewController. I want to switch to the other view controller (in this case SettingsViewController) when I press the button.
The strange thing is that when I press the button, the animation that flips the controllers goes well, but when it finishes I obtain the EXACT same things that I had on the RootViewControllers (same custom views, same buttons, same all!). The question is: what I'm missing?? I have to say that I use ARC (automatic reference counting) so I can't release or dealloc the views and buttons I've created on my RootViewController.
Any help will be appreciated. Thank you all!
Pushing and and modally presenting view controllers does not deallocate the view controller that presented them. It simply adds the additional view controller to the stack. You'll need to implement a callback method so that when the user hits the button to flip back to root view controller, your settings view controller lets the root view controller know what's about to happen so you can call a method you've written to reset the interface back to whatever state you need it at. You may also be able to use viewWillAppear: but that's a little messy.
However, according to the Apple Human Interface Guidelines, the user expects that when they push a view controller or modally present it, the view controller they were on will save state and be exactly the way they left it when they came back. It's disconcerting and annoying when state is not preserved while in a navigation controller context. It is especially annoying when it's modally presented.
Think about this - A user is in a hypothetical Mail app. They start typing out an email and set a font size and a color. They tap on the add attachment button, which brings up a modal view controller that allows them to select a picture. They select the picture and the modal view is dismissed, and in your implementation, the mail composing interface would have reset and the email content would be gone or at the very least the selected font size and color would be back to the default. That's not a good experience.