0

UIBarButton である nextButton を押すと。その後、関連付けられたアクションは実行されません。

UIButton *nextButton1=[UIButton buttonWithType:UIButtonTypeCustom];
[nextButton1 setBackgroundImage:[UIImage imageNamed:@"next.png"] forState:UIControlStateNormal];
[nextButton1 addTarget:self action:@selector(goToItems) forControlEvents:UIControlEventTouchUpOutside];
[nextButton1 sizeToFit];

UIBarButtonItem *nextButton=[[UIBarButtonItem alloc]initWithCustomView:nextButton1];
self.navigationItem.rightBarButtonItem=nextButton;
4

3 に答える 3

5
[nextButton1 addTarget:self action:@selector(goToItems) forControlEvents:UIControlEventTouchUpInside];

あなたは合格UIControlEventTouchUpOutsideしているはずですUIControlEventTouchUpInside

于 2012-07-06T10:35:38.393 に答える
0

明らかな間違いはUIControlEventTouchUpOutside、 に変更する必要があることUIControlEventTouchUpInsideです。

ただし、別個のボタンを作成してビューとして に割り当てる代わりに、目的のイメージで を作成し、目的のアクションをそれに関連付けるUIBarButtonItemことができます。UIBarButtonItem

例えば:

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"next.png"]
                                                               style:UIBarButtonItemStylePlain
                                                              target:self 
                                                              action:@selector(goToItems)];

self.navigationItem.rightBarButtonItem = nextButton;

[nextButton release];
于 2012-07-06T11:19:49.803 に答える
0

その使用の代わりに forcontrolevent を UIControlEventTouchUpoutside として渡しました

[nextButton1 addTarget:self action:@selector(goToItems) forControlEvents:UIControlEventTouchUpInside];

[nextButton1 addTarget:self action:@selector(goToItems) forControlEvents:UIControlEventTouchUpInside];
于 2012-07-06T10:39:21.437 に答える