0

我有 C++ 经验,我需要知道如何使按钮转到我创建的 void 方法。

这基本上就是我的按钮

-(IBAction)Button:(id)sender {
}

如果没有办法这样做,那么有没有办法将按钮链接到警报视图?

我将不胜感激任何反馈。

4

3 回答 3

1

希望这会帮助你。

UIButton *myButton=[[UIButton alloc] initWithFrame:CGRectMake(1.0f , 720.0f, 50.0f, 50.0f)];
[myButton addTarget:self action:@selector(myButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

- (void)myButtonTapped:(id)iSender {
    //Code For Button Action
}
于 2013-07-03T03:42:37.570 回答
1

您需要确保-(IBAction)Button:(id)sender在您的 中定义@interface,然后在 Interface Builder 中,右键单击并从您的 Button 对象拖动到File's Owner,然后选择(your IBAction)Button:

在此处输入图像描述

在里面显示警报IBAction

-(IBAction)Button:(id)sender
{
    UIAlertView *_alert = [[UIAlertView alloc] initWithTitle:@"Some title" message:@"Some message." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
    [_alert setTag:1];
    [_alert show];
    [_alert release];
}
于 2013-07-03T03:23:25.220 回答
0

尝试这个

/* UIButton programmatically from a IBAction */
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(10,10,50,50);
[button addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

-(IBAction)buttonTouched:(id)sender
{
    NSLog(@"New Button Clicked");
}
于 2013-07-03T03:55:34.810 回答