您可以直接選擇到任何目標 - 之所以通常,self
是目標,因爲這是很正常的代碼實例化一個的UIButton /的UIBarButtonItem,所以很多教程包括實現在選擇參考資料同班。
你可以,例如,使一個類,在您的視圖控制器實例化時,僅設計爲處理這些按鈕調用操作:
#import <UIKit/UIKit.h>
#import "OtherObject.h"
@interface SomeViewController : UIViewController
@property (strong, nonatomic) OtherObject *other;
@end
@implementation SomeViewController
@synthesize other;
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *someButton = [[UIButton alloc] initWithFrame:CGRectZero];
[someButton addTarget:other action:@selector(someMethodInOther) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:someButton];
UIButton *anotherButton = [[UIButton alloc] initWithFrame:CGRectZero];
[anotherButton addTarget:other action:@selector(anotherMethodInOther) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:anotherButton];
}
@end
IBAction爲可讓您在Interface Builder中這個方法的實現可以連接通過你的xib/storyboard。
謝謝!!!!!!!!!! – SpeedBirdNine 2012-07-09 12:22:52