1.点击事件后就注册通知:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSUInteger row = [indexPath row]; if (row > 2 && row < 7){ // [self ModifyWiFiInfoAlter]; NSString *okMsg = @"SureToModify"; NSString *cancleMsg = @"CancelToModify"; //OKClick cancelClick [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OKClick:) name:okMsg object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cancelClick:) name:cancleMsg object:nil]; UIStoryboard *board = [UIStoryboard storyboardWithName:@"WifiSetup" bundle:nil]; WiFISetupDetailController *WiFi_Info_Modify_VC = [board instantiateViewControllerWithIdentifier:@"WiFi_Info_Modify_VC"]; WiFi_Info_Modify_VC.infoDic = _infoDic; WiFi_Info_Modify_VC.showType = _showType; [self addChildViewController:WiFi_Info_Modify_VC]; [self.view addSubview:WiFi_Info_Modify_VC.view]; [WiFi_Info_Modify_VC didMoveToParentViewController:self]; } }
2.弹出框所在的controller:
- (IBAction)modifyWiFiInfoOKClick:(UIButton *)sender { NSLog(@"encrypt text:%@,channel text:%@",_encryption_text.text,_wifi_channel_text.text); _wifi_channel_text.text = [_infoDic objectForKey:@"WiFi Channel"]; _encryption_text.text = [_infoDic objectForKey:@"Encryption"]; NSLog(@"OK Button"); NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSString *okMsg = @"SureToModify"; [center postNotificationName:okMsg object:_infoDic]; } - (IBAction)modifyWiFiInfoCancelClick:(UIButton *)sender { NSLog(@"Cancel Button"); NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSString *cancleMsg = @"CancelToModify"; [center postNotificationName:cancleMsg object:nil]; }
3.接收反馈
#pragma mark - Modify WiFi info acion - (void) cancelClick:(NSNotification*)notification{ UIViewController *vc = [self.childViewControllers lastObject]; [vc.view removeFromSuperview]; [vc removeFromParentViewController]; [self removeModifyNotification]; } - (void) OKClick:(NSNotification*)notification{ NSMutableDictionary *dic = [notification object]; UIViewController *vc = [self.childViewControllers lastObject]; [vc.view removeFromSuperview]; [vc removeFromParentViewController]; [self removeModifyNotification]; // WIFI SSID NSString *ssid = [dic objectForKey:@"SSID"]; NSString *password = [dic objectForKey:@"Password"]; NSString *channel = [dic objectForKey:@"WiFi Channel"]; // NSString *powerLevel = [dic objectForKey:@"WiFi Strength"]; NSString *encrypt_str = [dic objectForKey:@"Encryption"]; NSLog(@"ssid:%@,pwd:%@,channel:%@,encrypt:%@",ssid,password,channel,encrypt_str); //WIFI 密码。可选。 //如果加密方式为OPEN,则无须设置密码 //如果加密方式为SHARED,密码长度必须为13位 //如果加密方式为其他,密码长度必须为8-63位 HwWifiEncryptMode encrypt = _toSetWifiInfo.encrypt; if (encrypt == kHwWifiEncryptModeOpen) { password = @""; }else if (encrypt == kHwWifiEncryptModeShared){ if(password.length == 0 || password.length !=13){ [MBProgressHUD showToast:self.view content:@"The password must contain 13 characters"]; return; } }else{ if (password.length == 0 || password.length < 8 || password.length > 63) { [MBProgressHUD showToast:self.view content:@"The password must contain 8 to 63 characters"]; return; } } NSLog(@"set wifi pwd:%@",password); _toSetWifiInfo.ssid = ssid; _toSetWifiInfo.password = password; // _toSetWifiInfo.powerLevel = powerLevel; _toSetWifiInfo.channel = channel; // _toSetWifiInfo.encrypt [self setWifiInfo:_toSetWifiInfo]; } -(void) removeModifyNotification{ NSString *okMsg = @"SureToModify"; NSString *cancleMsg = @"CancelToModify"; [[NSNotificationCenter defaultCenter]removeObserver:self name:okMsg object:nil]; [[NSNotificationCenter defaultCenter]removeObserver:self name:cancleMsg object:nil]; }
相关推荐
4. **键盘管理**: 当用户输入消息时,键盘弹出可能会遮挡输入框。为解决这个问题,可以使用`NSNotificationCenter`监听`UIKeyboardWillShowNotification`和`UIKeyboardWillHideNotification`通知,获取键盘的高度...
// 弹出消息框提示用户的逻辑 } ``` 至于推送消息到来时播放震动声音的效果,可以使用`AudioToolbox`框架中的`AudioServices`。以下是一个简单的实现: ```swift import AudioToolbox // 初始化声音ID var ...
例如,当键盘弹出时,可以将输入框向上移动,键盘隐藏时再恢复原位。这通常涉及到界面布局的动态调整,可以使用AutoLayout或者Size Classes来实现。 总结,动态获取键盘高度在iOS应用开发中是一个常见的需求,通过...
1. **监听键盘的通知**:在需要响应键盘事件的控制器中注册键盘显示和隐藏的通知,以便能够在键盘弹出或隐藏时作出相应的处理。注册通知的方法如下: ```objective-c [[NSNotificationCenter defaultCenter] ...
通过学习和实践“XamarinIOSDemoKeyboardHandler”项目,开发者不仅可以掌握Xamarin.iOS的基础,还能深入了解如何优雅地处理键盘事件,提升iOS应用的用户体验。这是一项实用的技能,对于任何涉及大量用户输入的iOS...
在iOS开发中,实现QQ登录界面并利用AppDelegate进行值传递是一项常见的任务。QQ登录通常涉及到第三方账号集成,这里我们主要关注QQ SDK的集成以及AppDelegate的角色。以下是对这一知识点的详细阐述: 1. **QQ SDK...
这通常用于响应iOS设备上的键盘行为,如调整视图控制器中的视图布局,以便在键盘弹出时不会遮挡输入字段。 ##### 1.1 KeyboardProtocol协议 定义了一个`KeyboardProtocol`协议,其中包含两个必需的方法:`...
- **UIAlertView**:UIAlertView是一个弹出窗口,用于向用户提供信息或请求确认。 - **配置与显示**:设置标题、消息内容、按钮等,然后调用`show`方法显示。 **2.2 使用UISwitch创建和使用开关** - **UISwitch...
5. **导航条操作**:`pushViewController:animated:`用于将新控制器推入栈中,`popViewControllerAnimated:`用于弹出栈顶控制器。`popToRootViewControllerAnimated:`和`popToViewController:animated:`则可以跳转到...
3. **键盘动画**: 当键盘弹出时,输入框应该随着键盘一起滑动,以保持用户可见。这可以通过监听UIKeyboardWillShowNotification和UIKeyboardWillHideNotification通知来实现。在接收到通知时,调整输入框和视图的...