简体   繁体   English

动态创建uibarbutton剂量工作

[英]Dynamically create uibarbutton dosent work

uibarbutton not responding. uibarbutton没有响应。

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" 
                               style:UIBarButtonItemStylePlain target:nil action:nil];

When ever user tap the button then no any actions fire. 只要用户点击按钮,便不会触发任何动作。

For that you need also use following code for the UIbarbutton. 为此,您还需要对UIbarbutton使用以下代码。

UIBarButtonItem *cameraView = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
                               target:self action:@selector(showCam)];

Or Also you can use following code. 或者您也可以使用以下代码。

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                        style:UIBarButtonItemStylePlain
                                        target:self
                                                                              action:@selector(showCam)];

it may also helping to you. 它也可能对您有帮助。

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"TITLE"
                                       style:UIBarButtonItemStylePlain
                                       target:self
                                       action:@selector(methodName:)] autorelease]; 

You need to specify a delegate that will handle the button callbacks (the 'target' parameter, typically, 'self', and the name of the method to be invoked, which is the 'action' parameter). 您需要指定一个将处理按钮回调的委托(“ target”参数,通常是“ self”,以及要调用的方法的名称,即“ action”参数)。

backButton = [[UIBarButtonItem alloc]
                 initWithTitle:@"Back"
                     style:UIBarButtonItemStylePlain
                     target:self
                     action:@selector(backButtonAction:)];

Include the action method, 'backButtonAction' in the class specified as the target. 在指定为目标的类中包括动作方法“ backButtonAction”。 So, if using 'self', include the method in the same class that's adding the button, as follows 因此,如果使用“ self”,则将方法包含在添加按钮的同一类中,如下所示

- (void) backButtonAction:(id) sender
{
    NSLog (@"backButtonAction: Sender %p", sender);

    ....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM