开发者

Custom UIToolbar buttons not clickable

I've an UITabBarController application with the first controller as navigation control开发者_如何学JAVAler. I subclassed UIToolbar:

CustomToolbar.h

#import <UIKit/UIKit.h>

@interface CustomToolbar : UIToolbar
{
    UINavigationController *navigationController;
}

@property (nonatomic, retain) UINavigationController *navigationController;

- (void)pressButton:(id)sender;

@end

CustomToolbar.m

#import "CustomToolbar.h"
#import "AnotherViewController.h"

@implementation CustomToolbar

@synthesize navigationController;

- (void)pressButton:(id)sender
{
    AnotherViewController *viewController = [[AnotherViewController alloc] init];
    [self.navigationController pushViewController:viewController animated:YES];
    [viewController release];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // add buttons
        UIBarButtonItem *mybutton = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(pressButton:)];
        [mybutton setEnabled:YES];

        // add buttons to the array
        NSArray *items = [NSArray arrayWithObjects:mybutton, nil];

        [self setItems:items];
        [mybutton release];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

MyViewController.m

[...]
CustomToolbar *myToolbar = [[CustomToolbar alloc] initWithFrame:CGRectMake(0, 436, self.navigationController.view.frame.size.width, 44)];
[self.navigationController.view addSubview:myToolbar];
[self.navigationController.view setFrame:CGRectMake(0, 0, self.navigationController.view.frame.size.width, self.navigationController.view.frame.size.height - myToolbar.frame.size.height)];
[...]

All works fine, I see the toolbar and the button BUT it isn't clickable. Any ideas here?

EDIT

I've found the problem. It happens because I resize the navigation controller frame. But I need to resize it. Solutions?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜