UIToolbar中的我的项目无法完全响应userInteraction?

时间:2011-04-02 03:42:34

标签: iphone objective-c ipad interface-builder

    UIToolBar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 1024, 44)];
    toolBar.barStyle = UIBarStyleBlack;
    [self.view addSubview:toolBar];
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"testText                      " style:0 target:nil action:nil];
    UIBarButtonItem *barButtonDateItem = [[UIBarButtonItem alloc] initWithTitle:@"  _________  " style:1 target:self action:@selector(dateButtonSelected)];
    UIBarButtonItem *barButtonItem2 = [[UIBarButtonItem alloc] initWithTitle:@"                         " style:0 target:nil action:nil];
    UISearchBar *searchBar1 = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 280, 100)];
    UIBarButtonItem *barButtonSearchItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:0 target:nil action:nil];
    barButtonSearchItem.customView = searchBar1;
    barButtonSearchItem.width = 280;
    NSArray *array = [[NSArray alloc] initWithObjects:barButtonItem,barButtonDateItem,barButtonItem2,barButtonSearchItem,nil];

    [barButtonItem release];
    [barButtonDataItem release];
    [barButtonItem2 release];
    [searchBar1 release];   
    [barButtonSearchItem release];

    toolBar.items = array;

    [array release];

当我点击barButtonDataItem或barButtonSearchItem时,该项目的一小部分可以响应我的点击操作;下半部分没有。 我该怎么办

谢谢!

1 个答案:

答案 0 :(得分:0)

如果您的视图包含tabBarController,则必须在tabBarController.view中添加工具栏而不是od self.view,如果没有tabBarController检查,则某些视图与您的工具栏重叠,这是不可见的。