Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:07:03+00:00 2026-06-09T01:07:03+00:00

I subclassed my navigation bar, making the title view clickable. When clicked, it will

  • 0

I subclassed my navigation bar, making the title view clickable. When clicked, it will present another view controller. I am creating a protocol in the navigation bar, that will tell the navigation controller that the title view has been clicked. Here is how my navigation bar is defined:

NavigationBar.h:

@protocol NavigationBarDelegate;

@interface NavigationBar : UINavigationBar
{
    id <NavigationBarDelegate> delegate;
    BOOL _titleClicked;
}

@property (nonatomic, assign) id <NavigationBarDelegate> delegate;

@end

@protocol NavigationBarDelegate
@optional
- (void)titleButtonClicked:(BOOL)titleClicked;
@end

The delegate implements one optional method. The .m file is as follows:

NavigationBar.m:

@implementation NavigationBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _titleClicked = 0;
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    self.tintColor = [UIColor colorWithRed:(111/255.f) green:(158/255.f) blue:(54/255.f) alpha:(255/255.f)];

    UIImage *image = [UIImage imageNamed:@"titlelogo.png"];

    UIButton *titleButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    titleButton.backgroundColor = [UIColor colorWithPatternImage:image];
    [titleButton addTarget:self action:@selector(titleButton:) forControlEvents:UIControlEventTouchUpInside];

    //        self.navigationController.delegate = self;
    [self.topItem setTitleView:titleButton];

    [super drawRect:rect];
}

- (void)titleButton:(UIButton *)sender
{
    _titleClicked = !_titleClicked;
    [self.delegate titleButtonClicked:_titleClicked];
}

This creates a navbar with a logo and calls the titleButton method when the title button has been clicked. Everything is fine up till here and the navigation bar displays nicely.

In my RootViewController:

NavigationBar *navigationBar = [[NavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 44.0f)];
navigationBar.delegate = self;
[self.navigationController setValue:navigationBar forKey:@"navigationBar"];

An implementation of titleButtonClicked is also there. When I click on the title view however, I get the following error: -[UINavigationController titleButtonClicked:]: unrecognized selector sent to instance

Why am I getting titleButtonClicked sent to UINavigationController? Is there something I need to do in my navigation controller? I am just using plain old UINavigationController. Do I need to subclass that too? If so, why?

EDIT:

Calling po self.delegate on line [self.delegate titleViewClicked:_titleClicked]; in NavigationBar.m yields the result below. How did the delegate change its type? How can I fix that?

(lldb) po self.delegate
(objc_object *) $1 = 0x07550170 <UINavigationController: 0x7550170>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:07:05+00:00Added an answer on June 9, 2026 at 1:07 am

    You have a clash/ambiguity between your delegate and UINavigationBar‘s delegate property. Rename your delegate to disambiguate them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My view controller will open modal view that is a UITableView subclass. UITableView subclass
I have a subclassed UIViewController that's acting as an ABPeoplePicker Navigation Controller Delegate. This
Let's say my main view controller will be a tab bar with misc sub
I have an app with a navigation bar at the top. On one view
I've created a subclassed TTPhotoViewController and presented modally in a navigation controller. When I
I have a storyboard based app with a navigation controller as the initial view
So I have a subclassed UITableView that lists data. I need to make only
I have a subclassed NSTextView that I am manipulating in a separate thread (using
I have a view controller managed in a UINavigationController. My view controller puts up
In short, I want to detect a touch on the navigation controller titlebar, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.