标签:
-(void)someButtonClicked{ // NSLog(@"点击成功!"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您点击了动态按钮!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",@"点击index",nil]; [alert show]; }
- (IBAction)btnTouch:(id)sender { CGRect frame = CGRectMake(90, 100, 200, 60); UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; someAddButton.backgroundColor = [UIColor clearColor]; [someAddButton setTitle:@"点击试试看!" forState:UIControlStateNormal]; someAddButton.frame = frame; [someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:someAddButton]; }
// // ViewController.m // btn_move // // Created by selfimprovement on 15-6-10. // Copyright (c) 2015年 sywaries@sina.cn. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController //监听方法 -(void)someButtonClicked{ // NSLog(@"点击成功!"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您点击了动态按钮!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",@"点击index",nil]; [alert show]; } //委托 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"buttonIndex:%d", buttonIndex); } //按钮action - (IBAction)btnTouch:(id)sender { CGRect frame = CGRectMake(90, 100, 200, 60); UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; someAddButton.backgroundColor = [UIColor clearColor]; [someAddButton setTitle:@"点击试试看!" forState:UIControlStateNormal]; someAddButton.frame = frame; [someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:someAddButton]; } //立马加载百度,可是被背景覆盖 - (void)viewDidLoad { [super viewDidLoad]; webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 240, 360)]; NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]; [self.view addSubview: webView]; [webView loadRequest:request]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)loadWebPageWithString:(NSString*)urlString{ } @end
UIAlertViewDelegate 就是添加委托
6 最后就是实现委托方法,目的就是知道您点击那一个index
//委托 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"buttonIndex:%d", buttonIndex); }
标签:
原文地址:http://blog.csdn.net/u010236550/article/details/46454545