I have a class called ToolbarView, which is a subclass of UIView and basically creates a UIView, in which the UIToolbar disappears / reappears on top. I also have a subclass of ToolbarView called DraggableToolbarView that allows the user to drag the view around the screen.
I need to create a delegate for the ToolbarView so that it can notify another object / class when the toolbar reappears and disappears. I also need to create a delegate for DraggableToolbarViewso that I can notify another object / class when dragging the view. The DraggableToolbarViews delegate should also notify another object / class when the toolbar reappears and disappears.
So, I decided to implement ToolbarViewDelegate, and I have DraggableToolbarViewDelegate inherited and has its own method:
ToolbarView.h
#import <UIKit/UIKit.h>
@protocol ToolbarViewDelegate;
@interface ToolbarView : UIView <UIGestureRecognizerDelegate>
{
id <ToolbarViewDelegate> _toolbarViewDelegate;
}
@property(nonatomic, assign) id <ToolbarViewDelegate> toolbarViewDelegate;
@end
ToolbarView.m
#import "ToolbarView.h"
#import "ToolbarViewDelegate.h"
...
- (void) showBars
{
...
if (self.toolbarViewDelegate)
{
[self.toolbarViewDelegate toolbarViewWillShowToolbar:self];
}
...
}
- (void) hideBars
{
...
if (self.toolbarViewDelegate)
{
[self.toolbarViewDelegate toolbarViewWillHideToolbar:self];
}
...
}
ToolbarViewDelegate.h
@class ToolbarView;
@protocol ToolbarViewDelegate
@required
- (void) toolBarViewWillShowToolbar:(ToolbarView *)toolbarView;
- (void) toolBarViewWillHideToolbar:(ToolbarView *)toolbarView;
@end
DraggableToolbarView.h
#import "ToolbarView.h"
@protocol DraggableToolbarViewDelegate;
@interface DraggableToolbarView : ToolbarView
{
id <DraggableToolbarViewDelegate> _draggableToolbarViewDelegate;
}
@property(nonatomic, assign) id <DraggableToolbarViewDelegate> draggableToolbarViewDelegate;
@end
DraggableToolbarView.m
#import "DraggableToolbarView.h"
#import "DraggableToolbarViewDelegate.h"
...
- (void)drag:(UIPanGestureRecognizer *)sender
{
...
if (self.draggableToolbarViewDelegate)
{
[self.draggableToolbarViewDelegate draggableToolbarViewWillDrag:self];
}
...
}
...
DraggableToolbarViewDelegate.h
#import "ToolbarViewDelegate.h"
@class DraggableToolbarView;
@protocol DraggableToolbarViewDelegate <ToolbarViewDelegate>
@required
- (void) draggableToolbarViewWillDrag:(DraggableToolbarView *)draggableToolbarView;
@end
SomeViewController.h
#import <UIKit/UIKit.h>
#import "ToolbarViewDelegate.h"
#import "DraggableToolbarViewDelegate.h"
@interface SomeViewController : UIViewController <ToolbarViewDelegate, DraggableToolbarViewDelegate>
{
}
@end
SomeViewController.m
#import "DraggableToolbarView.h"
...
- (void) toolbarViewWillShowToolbar:(ToolbarView*)toolbarView
{
}
- (void) toolbarViewWillHideToolbar:(ToolbarView*)toolbarView
{
}
- (void) draggableToolbarViewWillDrag:(DraggableToolbarView*)draggableToolbarView
{
}
...
[draggableToolbarView setDraggableToolbarViewDelegate:self];
...
When I do this, only the methods respond DraggableToolbarDelegate. However, when I also execute [drabbleToolbarView setToolbarViewDelegate:self], it works. I tried to do each delegate separately without inheritance, and it works great, so I believe that the problem is not in any other part of the code.
Can anyone know why? I realized that to inherit the protocols, I also would not need to set ToolbarViewDelegate for the DraggableToolbar object.
UPDATE: much more code added