在UIToolBar上添加按钮(按代码)

Ant*_*ope 1 objective-c xcode4

如何通过按钮上的代码添加到我拥有该属性的工具栏?

@property (strong, nonatomic) IBOutlet UIToolbar *toolB;
Run Code Online (Sandbox Code Playgroud)

Joh*_*ato 11

UIBarButtonItem *buttonOne = [[UIBarButtonItem alloc] initWithTitle:@"Button One" style:UIBarButtonItemStyleBordered target:self action:@selector(action)];

UIBarButtonItem *buttonTwo = [[UIBarButtonItem alloc] initWithTitle:@"Button Two" style:UIBarButtonItemStyleBordered target:self action:@selector(action)];

NSArray *buttons = [NSArray arrayWithObjects: buttonOne, buttonTwo, nil];
[toolBar setItems: buttons animated:NO];
Run Code Online (Sandbox Code Playgroud)

如果我正确理解你的要求,我会做的.action是您希望按钮调用的方法.