Removing view from subview does not call willRemoveSubview - cocoa

I have a managing view controller that switches in one of a set of previously allocated sub view controllers when the user chooses a menu item.
When I switch in a view controller I hook up the view of the managing view controller to the view in the sub view controller.
[mvc.view addSubview:subvc.view];
It all seems to work fine.
However, when removing that sub view controller's view from the view hierarchy with (eg.. when switching pages in the application):
[subvc.view removeFromSuperview];
the willRemoveSubview method in the custom view class never fires. I've confirmed that when I make the removeFromSuperview call I am calling it on an instance of my custom view class.
Other methods in my custom view class do fire though, such as viewWillMoveToWindow.
The NSView reference doc says this method should be called?
Can anyone suggest why this isn't working?
I'm running on 10.8.2 compiling for 10.7 with Xcode 4.5.2
Thanks
Darren.

willRemoveSubview:, as the name suggests, is called on the super view, not the subview being removed.

Related

Xamarin Forms - Access Prism INavigationService in View Model for Content View

As part of a Xamarin.Forms application I have implemented a custom navigation header. The Navigation Header is simply a Content View that has its own View Model. Pages which need to participate in the navigation experience of the application include this content view within them.
This application is using Prism 7 and to perform navigation within View Models I would like to use the Prism INavigationService. The issue I have with this is getting a reference to the INavigationService inside the View Model for the navigation Content View.
Accessing the INavigationService in a ContentPage is trivial, simply have this injected using constructor injection, the problem is that injecting INavigationService into the View Model for a Content View is not possible using prism 7 - this is confirmed by Brian Lagunas in his reply to this topic on the Xamarin Forums.
In his response Brian quotes as follows:
You can't inject the INavigationService into a ContentView's VM. You should either expose a property that you can bind to from your VM, or set it in code when the ContentView is loaded.
With the above in mind, what would be the approach to getting a reference to the INavigationService in the View Model of a Content View? I already have the wiring of the Content View to its View Model working correctly.
You already mentioned that there is no way to use INavigationService in your View Model for Content View (your custom control).
One of the easiest and simplest ways to resolve this is by adding bindable command in your Content View (custom control), having this bindable command you will be able to use that command and bind to it from ViewModels of your pages.
With this approach you can use INavigationService in your page ViewModel in a standard way and navigate from page based on command execution in your ContentView.
In other words you can handle your navigation from ViewModel when that command from reusable view is executed.
There is a lot of examples how to achieve this, you can use this one from another SO thread.
Wishing you lots of luck with coding!

How to add a URL link using storyboard

I have created via Storyboard, a Navigation Controller connected to a Table View Controller where each table cell is linked to a different View Controller. One one of these View Controller I would like to put a URL, can I do this in Storyboard ?
Thank you.
You mean you want to click on one table cell so it takes you to a website directly outside of your app ? or to a web view inside your app ?
Since you're asking about a way to do this using Storyboard, I suggest putting a WebView inside your View Controller.

In a single page desktop-like application, should I dynamically instanciate a controller for a window? How?

I'm asking this because I really don't know where I should handle events of my dynamically created window.
When someone clicks on a desktop icon, the window (if it doesn't exist) will be dynamically created. Should I create a controller when creating the window and hook to it? If yes, how?
Here you can read different approaches I've thought about:
Create a controller that will instanciate the Window (as its view), I will handle everything there
Create the window only and hook everything in my taskbar controller (which is where the window is created). In this case, the Taskbar controller will become very big.
Pre-create all window controllers and eventually windows too and hide them (when page is ready). Then just show/hide them, so I will have "static" references to all controllers with getController in Application
Which approach should I use?
Edit 1:
I'm trying to dynamically instanciate (and reference it through another controller) a controller. I'm having hard time expecially in referencing it. Any suggestion on how it should be done?
I found Ext's MVC unusable with desktop demo as it's possible to have multiple windows (views) of the same type tied to a single controller. Each window has it's own state and it's hard to differentiate between the views in the controller.
I solved the problem by myself: I preinstanciate the controller as I do with all controllers, by inserting them in Application controllers array. After this, I instanciate the view on that controller when a method is called, then I simply use refs to access this view.
The method is quite clean and using refs feel so good. Obviusly the controller has a method hasWindow which checks if the controller view has been created already.

Disconnected view from View in interface builder iOS

I am working on my signInViewController.xib file and I accidentally disconnected the view from View in files owner. How do I fix this?
You mean you accidentally disconnected the view from the View Controller, yes?
If that's the case, control drag from the View Controller object to your view and one of the connections you can make is the View one.
If you actually mean that the File Owner for the XIB is no longer the View Controller, go to the Attributes Inspector for the File Owner and set the "Custom Class" attribute to the name of your View Controller class.
A nice visual description of the architecture is in this Apple documentation, in Figure 2-4.
Hope this info helps!

Adding a UINavigationController built with IB

Building an iPhone application. The delegate loads a SplashScreenView which sits there until the user taps the screen. When the user is done tapping the screen, I release that view and I want to load my custom Navigation Controller. I can't figure out how to load the Navigation Controller I designed in IB...it's currently loading a blank instance of UINavigationController.
I'm running this from my delegate:
mnc = [[MyNavigationController alloc] initWithNibName:#"MyNavigation" bundle:nil];
[self.window addSubview:mnc.view];
MyNavigation is a XIB I created which only has File's Owner/First Responder/a Navigation Controller I added. I set the class of File's Owner to MyNavigationController but I'm not sure how to tell it that I want the view "MyNavigationController" uses to be the one I designed. When I try to drag the "view" outlet of File's Owner in IB to my designed Navigation Controller, it doesn't seem to like it.
I'm just not sure how to connect the dots here. Any help would be incredibly appreciated.
What is the root controller of your navigation controller? The "blank" thing that you see is probably your navigation controller loaded with no controllers for it to navigate.
Update
You don't need "two controllers" per se. It's just that navigation controller is the one that controls the stack of other controllers you provide it with. First you init your navigation controller with root view controller (with initWithRootViewController method you mentioned), then you can push (pushViewController:animated:) or pop (popViewController:animated:) other controllers to or off of the stack of navigation controller.
Apple developer documentation provides plenty information in view controller programming guide on how different types of view controllers interact.

Resources