01-学习iOS的动态添加Button和监听UIAlertView按钮的点击事件()
来源:互联网 发布:源码加密php 编辑:程序博客网 时间:2024/05/21 11:19
1、在h文件中定义,第一个按钮对应-(IBAction) addButton:(id)sender; 并在m文件中实现它。
-(IBAction)addButton:(id)sender{
CGRect frame = CGRectMake(90,200, 200, 60);
UIButton *someAddButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
someAddButton.backgroundColor = [UIColorclearColor];
[someAddButtonsetTitle:@"动态添加一个按钮!" forState:UIControlStateNormal];
someAddButton.frame = frame;
[someAddButtonaddTarget:selfaction:@selector(someButtonClicked)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:someAddButton];
}
这里还涉及到第二个方法someButtonClicked。
2、我们下面实现它
-(void) someButtonClicked{
UIAlertView *alert = [[[UIAlertViewalloc] initWithTitle:@"提示"
message:@"您点击了动态按钮!"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:@"第二项",@"第三项",nil] autorelease];
[alertshow];
}
以上两个方法实现对第一个按钮的监听,在第一个按钮被点击之后,动态生成第二个按钮; 如果在点击第二个按钮,则弹出提示信息框。
下面要实现对UIAlertView的监听。
3、首先要在h文件遵守协议<UIAlertViewDelegate>,具体代码是
@interface ViewController :UIViewController<UIAlertViewDelegate>
.........
@end
在m文件中实现alertView的若干方法,这里只实现一个方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@" button index=%d is clicked.....", buttonIndex);
}
- 01-学习iOS的动态添加Button和监听UIAlertView按钮的点击事件()
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- IOS-监听UIAlertView按钮的点击事件
- iOS学习基础学习之动态添加Button和监听UIAlertView按钮
- ios学习笔记:UIAlertView使用和监听点击事件
- Button的监听事件和点击效果
- iOS-UIAlertView的点击事件
- 为UIAlertView上的按钮添加方法,需要重写协议中对话框按钮点击事件方法
- 监听按钮的点击事件
- 监听按钮的点击事件
- 监听按钮的点击事件
- 监听按钮的点击事件
- 监听按钮的点击事件
- ios 动态添加了按钮,绑定同一个点击事件,如何判断点击的是哪个?
- iOS--- 动态添加了按钮,绑定同一个点击事件,如何判断点击的是哪个?
- 05-frameLayout布局方式实例
- win32 select学习
- 小白7.2.1
- Java学习总结之坦克大战项目(完结版)
- 10 个学习iOS开发的最佳网站
- 01-学习iOS的动态添加Button和监听UIAlertView按钮的点击事件()
- HDU 1710 Binary Tree Traversals
- 使用 Android 自带的 proguard 混淆源码
- Neo4j文件说明
- POJ 1966 - Cable TV Network 暴力枚举+最小点割
- ubuntu开启SSH服务
- android菜单三级树实现
- 创新工场笔试题
- 求最长上升子序列的长度