UIAlertView 简单使用, NSNotification键盘监听(零碎内容)

UIAlertView 简单使用

// 点击tableViewCell时弹出UIAlertView
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LFHero *hero=self.heros[indexPath.row];
    
	// 新建 UIAlertView类 , init时,设置,alertView代理为self,需实现UIAlertViewDelegate协议
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"修改数据" message:hero.intro delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    alertView.alertViewStyle=UIAlertViewStylePlainTextInput; // 设置alertView样式。
	
	alertView.tag=indexPath.row; // 设置alertView tag属性
 
    UITextField *textField = [alertView textFieldAtIndex:0]; //提取alertView中的textField
    textField.text=hero.name;
    [alertView show];
    
    NSLog(@"%@", [[alertView textFieldAtIndex:0] text]);

}


UIAlertViewDelegate需要实现,

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;方法(当点击alertView中的按钮时,会触发)

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex==1){
      // 点击确定
        int row=alertView.tag;
		LFHero *hero1 = self.heros[row];
        UITextField *textFile=[alertView textFieldAtIndex:0];
        [hero1 setName:textFile.text];
        
        
        NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];
        // 刷新指定行
        [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationRight];
        // 刷新整个tableView
		[self.tableView reloadData];
		
    }else{
        // 点击取消
    }
   }




NSNotification键盘监听

//     注册键盘尺寸监听的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];

监听方法为keyboardWillChange:

#pragma 键盘监听的通知执行方法
-(void)keyboardWillChange:(NSNotification *)notification{
    
    NSDictionary *dict  = notification.userInfo;
    NSLog(@"dict"); // 其中为键盘的各种信息
	// 根据notification.userInfo中的NSDictionary 来选择需要这行的动作
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dwt1220

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值