我在做navigationController的时候,我想要标题有一个点击事件,我查了网上的例子,他说使用self.navigationItem.titleview = [uibutton], 我在代码里面添加了uibutton,然后button也设置了点击事件,但是显示的时候,它显示了button的名字,但是却没有button的点击事件,所以请教各位大牛,谢谢

解决方案 »

  1.   

    uibutton 创建成custom试试。button的点击事件你要把button放在最上面。其实创建一个control就可以了。
      

  2.   

    addTarget: action:@selector(SEL)来添加事件关联
      

  3.   

    学习下, self. self.navigationItem push....:xxxView;
      

  4.   

    我给你写了个 希望你能看明白
    UIButton *titleBtn = [[UIButton alloc]initWithFrame:CGRectMake(110,0,100,44)];
        [titleBtn setTitle:@"切换城市" forState:0];
        [titleBtn addTarget:self action:@selector(goSelectCity) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.titleView = titleBtn;
        [titleBtn release];-(void)goSelectCity
    {
    //你要干的事
        [self dismissModalViewControllerAnimated:YES];
    }
      

  5.   

    [titleBtn addTarget:self action:@selector(goSelectCity) forControlEvents:UIControlEventTouchUpInside];楼上正解
      

  6.   

    那个btn是在栈里面的,self.navigationItem.titleView = titleBtn;在多数情况下不好使。