从childViewController创建的栏按钮不起作用

时间:2013-07-21 13:58:29

标签: uisearchbar uibarbuttonitem parentviewcontroller childviewcontroller

我有parentViewContoller(使用UINavigationItem)和childViewContoller(使用UITableViewContoller,UISearchBar)。我想在点击searchBar隐藏时创建UIBarButtonItem。

TableViewContoller.h(childViewContoller)

@interface TableViewController : UITableViewController<UISearchBarDelegate, UISearchDisplayDelegate, UINavigationControllerDelegate> 
@property (nonatomic, strong) IBOutlet UISearchBar *searchBar;
@end

TableViewContoller.m(childViewContoller)
@synthesize searchBar;

- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.searchBar.hidden = NO;
    [self createSearchButton];
}
- (void) createSearchButton {
    UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"myButton" style:UIBarButtonItemStyleBordered target:self action:@selector(iButton:)];
    self.parentViewController.navigationItem.rightBarButtonItem = myButton;
}

-(void) iButton {
    self.searchBar.hidden = YES;
    NSLog(@"Click on iButton");
}

但是,如果我单击myButton,将显示NSLog,并且不会隐藏searchBar。为什么我的代码不起作用?

0 个答案:

没有答案
相关问题