Segues from a subView - ios

Just trying to teach myself storyboarding and have run into a question I was hoping people may have an answer to.
I wanted to create a reusable upper toolbar so that in case I ever had to change it, it would update all of my scenes. I created a sized ViewController in my storyboard. I then load it into a subview of each of my scenes using the menu's identifier. THat seems to work pretty well (although, feel free to tell me that's the wrong way to do it).
Here's where the problem starts. On that top toolbar, I have a UIButton which I connect to another sized ViewController in my storyboard as a popover. Basically, a drop down menu. If I just load up the top toolbar, works fine. If I connect just a regular button to that popover scene using a segue, that works too. If, however, I try to click the button and follow the segue while the toolbar is within a subView I crash with EXC_BAD_ACCESS. I presume I'm not allowed to spawn a popOver from a subView or follow a segue within a subview? The latter seems wrong since you effectively do that with any UI object.
How else should I handle this?
Thanks!

I'd recommend using a UINavigationController and setting the toolbar to include your UIButton (as a UIBarButtonItem). If you have any trouble "keeping track" of the toolbar or button you can subclass UINavigationController, add the UIButton (or entire toolbar) as a property of the subclass, and access it from any subsequent view through the self.navigationController property (might violate strict OO, but you could use a protocol).
As for the popover, I think you're OK on iPad but not on iPhone. There are custom projects on github to implement UIPopoverController, and indeed the Facebook app makes use of a custom popover for notifications in their app. iPhone raises an exception if you try to show a UIPopoverController.

Related

selectedViewcontroller not working for tabbarcontroller in tvOS 10

I have a rootviewcontroller which is extending UITabBarController. It has several children viewcontrollers.
All I want is to programmatically select the 2nd/3rd/.. viewcontroller from the first one. I've used
`.selectedViewController`, `.selectedIndex`, `.navigationController.tabBarController.tabBar.selectedItem = ...`
and all the variations on this theme. I notice the following when using
`tabBarController.selectedViewController = tabBarController.viewControllers?[1]`
The tabBarController displays the 2nd viewcontroller for a second but goes back to the 1st viewcontroller. I have a hunch this is the focus engine but I'm lost at this point.
Not completely sure if it's related but I had a tvOS app where I had several UIViewControllers in a UITabBarController and I stopped being able to select them in the tab bar and have the tab bar go away once I upgraded to tvOS 10.
Turns out the issue is that those screens did not have any focusable elements on them (buttons, etc.) so I had to make subclass objects for some of the views and make the canBecomeFocused property return "true".
see: How to make a UIView focusable using the focus engine on Apple TV
You have to implement a second thing to make them appear focused but if you don't actually want that you can skip it.
I was setting an UITabBarItem for each controller.

ios methods becoming zombies

I added uiviewcontroller subclass in my arc enabled project, i added a button created the ibaction for it and inside it contains no code, all done through interface builder no manual code, but when i am tapping the button i am getting exc_bad_acess. Instrumentation saying its a zombie attack when pressing button. I really dont understand whats going wrong. I created the new project and done the same thing it is working perfectly. Same thing happening when i am defining method to dismiss keyboard (resign first responder).
this generated when i crtl+dragged from button to interface implementation, i choose the ibaction and name and this code is generated.
- (IBAction)pushh:(id)sender;
and the implementation inside .m file
- (IBAction)pushh:(id)sender {
}
thats all ...
Just to wrap up the offline conversation, a couple of thoughts:
Your zombie is undoubtedly a result of the ecnObj falling out of scope. If it's an ivar of the view controller, then that premature release problem goes away.
You do not want to create a new view controller and then use its view in transitionFromView. If you want to transition between view controllers (in iOS5) you should use pushViewController or presentViewController (or if you're using a container view controller, you can pursue transitionFromViewController). See View Controller Programming Guide's discussion of "Presenting View Controllers from Other View Controllers".
My solution was to delete the button iboutlet in ib, also delete the ibaction in ib, and then connect it back.

ipad, How to manage Popover presented from barbuttonitem?

I know that UIPopovercontroller does not retain itself while presenting.So we have to keep a reference to it to keep it alive
And When pressing the barbuttonitem which is presenting a popover, it does not automatically dismiss the popover, it actually will present another popover over it again and again when you press the button and do nothing special to check if there was already some popover.
I know we can have many properties to maintain every barbuttonitem's popover, but I think this is ugly...
Is there any better practice?
I'm using popovers with ARC and have not had to do anything special to maintain the reference count. As long as the popover is onscreen, there are strong references to it to keep it alive. Do you have a fail case you could post?
I consider the second issue you mention the more interesting one: pressing the barButtonItem repeatedly creates multiple instances of the popover. It's difficult to see them, because they stack up atop each other. But the shadows around the popup get darker with each added instance. The real tipoff to the problem is that every instance has to be dismissed separately.
One solution is to disable/enable the UIBarButtonItem on the way into and out of the popup. This worked well for me, but is slightly tedious. (I had to put code in two places - one in my own dismisser, and another in the popoverController's delegate's – popoverControllerDidDismissPopover: method, for the case where the user clicked outside the popover to dismiss it.)
I think that the (excellent) Stanford CS193P course addresses this issue by hiding the button while the popup is showing.
The iOS behavior actually seems like a bug. A click in the barButtonItem is outside the popover, and unless the barButtonItem's view is included in the popover's passthrough array, it is supposed to (according to the doc) dismiss the popover. But it doesn't and Apple didn't ask me.
I just checked and found that the passthrough array is initially nil, so removing the barButtonItem's view from that array is not an option. Drat.

Visually modifying a UIToolbar from xcode storyboard

I'm using XCode 4 and storyboarding an application I'm creating, however I cannot visually modify the UIToolbar.
I'm attempting to modify a UIToolbar that is inside of a UITableViewController - however I have to place the UIToolbar out of the correct hierarchy in order to be able to modify it visually. I've tried placing it onto the view controller area but that does not make it show up.
At one point I was able to make it appear below, as it's own object however I was not able to recreate that.
Once I was able to get it to look like this
Your UITableViewController is inside a UINavigationController, which already has its own UIToolbar—you don't need to drag a new one into your view hierarchy. Interface Builder can simulate the toolbar for you under "Simulated Metrics" in the inspector panel.
Once the simulated toolbar is visible, simply drag UIBarButtonItems into it. Use a custom item with a custom view if you need anything more complicated than a button or spacer.
If you need your toolbar items need to be dynamic, you can maintain a reference via IBOutlets without necessarily having them in your view. Then set your UITableViewController's toolbarItems property or call -setToolbarItems:animated: at runtime to display the appropriate items.
See Apple's UINavigationController Class Reference: Displaying a Toolbar.
To answer your question, the visual editor simplifies the setup of most controls, view hierarchies, and delegation patterns, but it's still up to the developer to make sure they check out. The implementation of UITableViewController makes certain assumptions and assertions about its view hierarchy that Xcode does not enforce through the visual editor. Given that your desired view hierarchy is unsupported, I have to assume that the editor's behavior is either undefined or irrelevant. For a workaround, see Maxner's suggestion.
UITableViewControllers only allow one view object, which of course is UITableView. UITableViews are not cooperative for subviewing and they usually push everything into footers or headers. Something like this isn't possible:
-TableController
-Table
-Subview
-Another subview
UITableViewControllers are reduced to this:
-TableViewController
-Table
So you will need to use a UIViewController and declare a UITableView in there. Heres the Hierarchy you should use then:
- ViewController <Table's Delegate & Data Source>
- View
-Table
- Your UIToolbar
In your ViewController.h declare IBOutlet UITableView and connect Data Source and Delegate to the ViewController. Then simply add the UITableView implementations to your .m file and you're good to go.

iOS: UIViewController is Not Being Pushed Problem

I'm working on a new app where there is a "main" UIViewController with some UIButtons and once the user clicks on the buttons, the application is navigating to another UIViewController.
For some reason, the UIViewControllers are not opened, when you click on the button nothing happens. Several points that anyone who tries to help should be aware of
I'm using code and interface that are very similar to another app that I had created and is working fine (I triple checked the code, and it's the same in the area that makes the UIViewControllers navigation)
I triple checked the Interface Builder items and their connection to the IBOutlet us fine (view is connected to view, File's Owner is set correctly, etc...)
I inserted NSLogs to the UIViewController that is not being pushed and I can see that initWithNibName is being called, but viewDidLoad is not being called.
I'm using basic-simple code to create and push the UIViewController: alloc+initWithNibName and then presentModalViewController or pushViewController (none of them work) and as I said, in another app with the same mechanism it works fine.
I don't know where to look! Maybe I unchecked by mistake some "Enable" button in Interface Builder or something like that.
Did anyone encounter something like that or may have some new thought regarding to where I should be looking?
Hmm, strange. Things i can come up with now are: dit you call [super ] in your viewDidLoad?
Is it stacked behind another view? Run instruments to see if all the things on the pushed view are allocated, so you know if the whole view is loaded. And you use a navigation controller? than you use pushViewController. When you are not and want a model you use presentmodalviewcontroller.

Resources