A pretty basic question, but one that I'm having trouble finding a solid answer to. Perhaps I'm not looking in the right places?
I have a separate XIB file containing a UINavigationController. It's in a separate XIB so it can be loaded and displayed from a number of different points in my app.
You can see the layout of the XIB in the screenshot. Now here's the deal... I want that Cancel button to pop the UINavigationController, in any scenario. I would even be alright with providing that Cancel button as an Outlet, and forcing those who load the XIB to set the callback function.
What's the best method to set this up? It must be a common occurrence, and if I were building the UI programmatically, it wouldn't be a problem, but I'm new to designing in IB with separate XIB files.
I have a sneaking suspicion I need to subclass UINavigationController, provide an outlet for the UIBarButtonItem, and do something like:
I have a separate XIB file containing a UINavigationController. It's in a separate XIB so it can be loaded and displayed from a number of different points in my app.
You can see the layout of the XIB in the screenshot. Now here's the deal... I want that Cancel button to pop the UINavigationController, in any scenario. I would even be alright with providing that Cancel button as an Outlet, and forcing those who load the XIB to set the callback function.
What's the best method to set this up? It must be a common occurrence, and if I were building the UI programmatically, it wouldn't be a problem, but I'm new to designing in IB with separate XIB files.
Code:
- (void)showSyncWindow:(id)sender {
NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"SyncViewController" owner:self options:nil];
for (id object in nibViews) {
if ([object isKindOfClass:[MyNavigationController class]]) {
MyNavigationController *nav = (MyNavigationController *)object;
nav.cancelButton.target = self; // <-- The new lines
nav.cancelButton.action = @selector(popWithAnimation:); // <-- The new lines
[self presentModalViewController:nav animated:YES];
}
}
}