我正在尝试以编程方式添加和信息按钮到我的应用程序的导航。但是,它永远不会触发我正在注册的动作。
UIBarButtonItem* infoButton =[[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
[infoButton setTarget:self];
[infoButton setAction:@selector(infoButtonTapped)];
按钮显示在我的导航栏中,但点击它不会传递到infoButtonTapped
答案 0 :(得分:11)
将目标/操作添加到UIButton。当从UIButton设置时,条形按钮项的行为会有所不同。
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:@selector(infoButtonTapped) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:button];