我有 C++ 经验,我需要知道如何使按钮转到我创建的 void 方法。
这基本上就是我的按钮
-(IBAction)Button:(id)sender {
}
如果没有办法这样做,那么有没有办法将按钮链接到警报视图?
我将不胜感激任何反馈。
希望这会帮助你。
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
}
您需要确保-(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];
}
尝试这个
/* 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");
}