LoginSignup
0
0

More than 5 years have passed since last update.

UIBarButtonItem 使用 Custom View 時需要自己處理 User Interaction

Last updated at Posted at 2015-05-14

在用 UIBarButtonItem 的時候,要用 custom view, 發現加 target 和 action 都沒有用,無法觸發 action 所設定的 SEL 物件。

使用CustomView
UIBarButtonItem *item = [UIBarButtonItem initWithCustomView:customView];
item.target = self;
item.action = @selector(didSelectItem:);
self.navigationitem.leftbarbuttonitem = item

這時候 selector didSelectItem: 並不會如期被呼叫到。

需自己處理

The bar button item created by this method does not call the action method of its target in response to user interactions. Instead, the bar button item expects the specified custom view to handle any user interactions and provide an appropriate response.

UIKit Framework Reference > UIBarButtonItem Class Reference > - initWithCustomView:

在文件裡面提到,當使用這個 method 來初始化一個 UIBarButtonItem 的實例時,他們則期望開發者應該要自己處理使用者的互動,

參考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0