Question

I have two table view controllers. Say TableViewController1 and TableViewController2.

I push TableViewController2 when someone clicks on the TableViewController1's cell.

I set the TableViewController1's clicked cell's value as the TableViewController2's back bar button's title value.

According to the length of the TableViewController1 cell's string, the back bar button's length also get changing.

Is it possible to fix the width of the back bar button? I really need this, because I want to capture the tap events of the TableViewController2 navigation bar's titleView.

Back bar button's width affects the titleView's width. So I can not find the bounds of the titleView. Or is there any other way to find the bounds value of a titleView of Navigation bar?

Was it helpful?

Solution

Is it possible to fix the width of the back bar button?

As far as I know you can not edit this button.

Subclassing it would be the way to go, or you might want to truncate the title from the previous viewController. Alternatively you might want to replace with with a normal UIBarButtonItem like so:

- (void) viewDidLoad
{
    [super viewDidLoad];
    self.title = @”shortTitle.”;

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                            style:UIBarButtonItemStyleBordered
                            target:nil
                            action:nil];

    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top