Search code examples
iosdelegatescalendaruitabbarcontrolleruitoolbar

Putting another UIViewController's view within a "main" UIViewController -- delegate methods


I'm trying to make an application very similar to the iCal app on the iPhone.

To do this, I'm integrating 2 open source projects, Kal (https://github.com/klazuka/Kal) and GuiCocoa/Calendar (https://github.com/guicocoa/calendar), as well as my own coded "List" view segment.

I decided, since I need everything nested in a UINavigationController Stack, that the best way to achieve this 3 separate projects into one kind of thing, I would create something similar to the UITabBarController (in which you have 1 UIViewController Class which stores and nests other UIViewControllers -- HOWEVER, I want to use a custom UIToolbar with a UISegmentedControl to delegate between the different view controllers).

So the most major issue I am running into is the mis-delegation of actions. For example:

If I were to click one of the gridded dates, it kicks back the error:

-[UINavigationButton didSelectDate:]: unrecognized selector sent to instance 0x6c1aba0 or something similar.

Maybe my question should be: Is there a "subclass" of UITabBarController which I can implement my own UIToolbar, instead of the official UITabBar, etc?

Or if not, is there a way to specify that all clicks in the "subview" are to be delegated to functions from within the subview?

Thanks, rnc505


Solution

  • First off you can subclass a UIToolBar to customize it.

    #import <Foundation/Foundation.h>
    
    @interface CustomToolBar : UIToolbar
    {
    
    }
    
    @end
    
    
    #import "CustomToolBar.h"
    
    @implementation CustomToolBar
    
    @end
    

    and instead of calling:

    UIToolbar *toolbar = [[UIToolBar alloc] init];
    

    you call

    CustomToolbar *toolbar = [[CustomToolbar alloc] init]
    

    Your other option is to just change the delegate of the buttons as needed.