当我按Next按钮,这是UIBarButton。 不进行再相关的操作。
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;
[nextButton1 addTarget:self action:@selector(goToItems) forControlEvents:UIControlEventTouchUpInside];
你逝去的UIControlEventTouchUpOutside
,应该是UIControlEventTouchUpInside
你通过了forcontrolevent作为UIControlEventTouchUpoutside而不是使用
[nextButton1 addTarget:self action:@selector(goToItems) forControlEvents:UIControlEventTouchUpInside];
[nextButton1 addTarget:self action:@selector(goToItems) forControlEvents:UIControlEventTouchUpInside];
最明显的错误是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];