I have a very strange problem. I have custom view that contains a uilabel and unbutton. I am using it as the TitleView on a navigation controller. Inside this navigation controller is a TableViewController that has a search bar. I am using a delegate method in the custom view to send a message to the navigation controller when the button is pressed. The button doesn't respond unless the search bar is active. When the search bar is active when I touch the title I see a NSLog statement in the controller notifiying me that the button has been pressed but when the search bar is inactive it doesnt respond anymore. Im posting the code I used to set up the title in the nav bar.
-(void)setupNavBarTitle {
self.titleWithDownArrowView = [[TitleWithDownArrowView alloc] initWithFrame:CGRectMake(0,0, 250,44)];
self.titleWithDownArrowView.titleLable.text = @"All";
self.titleWithDownArrowView.delegate = self;
self.navigationItem.titleView = self.titleWithDownArrowView;
}
- (void)titleClicked {
NSLog(@"getting touched");
}
Here is my custom view .h file
@protocol DidSelectTitle <NSObject>
@required
-(void) titleClicked;
@end
@interface TitleWithDownArrowView : UIView
@property (strong, nonatomic) IBOutlet UIView *view;
@property (strong, nonatomic) IBOutlet UIButton *downArrowButton;
@property (nonatomic) id<DidSelectTitle> delegate;
@property (strong, nonatomic) IBOutlet UILabel *titleLable;
@end
custom view .m file
@implementation TitleWithDownArrowView
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[[NSBundle mainBundle] loadNibNamed:@"TitleWithDownArrowView" owner:self options:nil];
[self addSubview:self.view];
[self.downArrowButton addTarget:self.delegate action:@selector(titleClicked) forControlEvents:UIControlEventTouchUpInside];
[self setupViewAttributes];
}
retu self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[[NSBundle mainBundle] loadNibNamed:@"TitleWithDownArrowView" owner:self options:nil];
[self addSubview:self.view];
[self.downArrowButton addTarget:self.delegate action:@selector(titleClicked) forControlEvents:UIControlEventTouchUpInside];
[self setupViewAttributes];
}
retu self;
}
- (void) setupViewAttributes {
self.titleLable.textColor = [UIColor grazeWhiteColor];
self.view.backgroundColor = [UIColor grazeCrimsonColor];
}
