ios 按钮点击事件

学习ios开发,写一个按钮点击事件。响应点击,弹出alertview,显示按钮事件。
头文件注册click事件
代码很简单一个IBACTION.
-(IBAction)btnclick:(id)sender;


响应意见再M文件内

- (IBAction)btnclick:(id)sender
{
    // 强制转型为btn类型
    UIButton *btn =(UIButton *)sender;
    // 标题名称 带btn的tag
    NSString *btnString =[NSString stringWithFormat:@"Button tag %d",btn.tag];
    // 标题内容,获取到btn 的title,设置为alert的名称。
    NSString *btnTitle =    [btn currentTitle];
    //定义一个alertView 只有一个确定按钮
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:btnString message:btnTitle delegate:self cancelButtonTitle: @"OK" otherButtonTitles: nil];
    [alert show];
//    [alert release];
}



猜你喜欢

转载自hellorheaven.iteye.com/blog/1773429