1

I have parentViewContoller(with UINavigationItem), and childViewContoller(with UITableViewContoller, UISearchBar). I want create UIBarButtonItem on click that searchBar hiding.

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");
}

But, if I click on myButton, NSLog is displayed, and searchBar not hidden. Why my code don't work?

4

0 回答 0