IOS 弹框AlterView的使用(IOS8.0以前使用)UIAlertController(IOS9.0使用)
#pragma mark - 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.取得被点击这行对应的模型
MJHero *hero = self.heros[indexPath.row]; // 弹框
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"数据展示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; // 设置对话框的类型
alert.alertViewStyle = UIAlertViewStylePlainTextInput; // 取得唯一的那个文本框,显示英雄的名称
[alert textFieldAtIndex:].text = hero.name; [alert show]; // 绑定行号到alertView上
alert.tag = indexPath.row;
} #pragma mark - alertView的代理方法
/**
* 点击了alertView上面的按钮就会调用这个方法
*
* @param buttonIndex 按钮的索引,从0开始
*/
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == ) return; // 按钮的索引肯定不是0 // 1.取得文本框最后的文字
NSString *name = [alertView textFieldAtIndex:].text;
// int row = alertView.tag;
// NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];
// UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
// cell.textLabel.text = name; // 2.修改模型数据
int row = alertView.tag;
MJHero *hero = self.heros[row];
hero.name = name; // 3.告诉tableView重新加载模型数据
// reloadData : tableView会向数据源重新请求数据
// 重新调用数据源的相应方法取得数据
// 重新调用数据源的tableView:numberOfRowsInSection:获得行数
// 重新调用数据源的tableView:cellForRowAtIndexPath:得知每一行显示怎样的cell
// 全部刷新
// [self.tableView reloadData]; // 局部刷新
NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:];
[self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom];
}
IOS 9.0以上用UIAlertController 代替UIAlertView(实例转载)
- (void)viewDidLoad {
[super viewDidLoad];
// 创建一个BUTTON 点击显示弹框
UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
button.frame = CGRectMake(, , , );
// 给BUTTON 添加点击方法
[button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchUpInside)];
button.backgroundColor = [UIColor blueColor];
[self.view addSubview:button];
}
// button的点击方法
- (void)actionButton:(UIButton *)button
{
// 初始化一个一个UIAlertController
// 参数preferredStyle:是IAlertController的样式
// UIAlertControllerStyleAlert 创建出来相当于UIAlertView
// UIAlertControllerStyleActionSheet 创建出来相当于 UIActionSheet
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"静" preferredStyle:(UIAlertControllerStyleAlert)];
// 创建按钮
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
NSLog(@"注意学习");
}];
// 创建按钮
// 注意取消按钮只能添加一个
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) {
// 点击按钮后的方法直接在这里面写
NSLog(@"注意学习");
}];
// // 创建警告按钮
// UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction *action) {
// NSLog(@"注意学习");
// }];
//
// 添加按钮 将按钮添加到UIAlertController对象上
[alertController addAction:okAction];
[alertController addAction:cancelAction];
//[alertController addAction:structlAction];
// 只有在alert情况下才可以添加文本框
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"用户名";
textField.secureTextEntry = YES;
}];
// // 取出文本
// UITextField *text = alertController.textFields.firstObject;
// UIAlertAction *action = alertController.actions.firstObject;
// 将UIAlertController模态出来 相当于UIAlertView show 的方法
[self presentViewController:alertController animated:YES completion:nil];
}
IOS 弹框AlterView的使用(IOS8.0以前使用)UIAlertController(IOS9.0使用)的更多相关文章
- iOS弹框
IOS 弹框 如果直接弹出一个自定义的视图 可以选用第三方: MJPopup 弹出: if(!bandview) { bandview=[[[NSBundle mainBundle]loadNibNa ...
- Ios 弹框 MJPopup,KxMenu
IOS 弹框 如果直接弹出一个自定义的视图 可以选用第三方: MJPopup 弹出: if(!bandview) { bandview=[[[NSBundle mainBundle]loadNibNa ...
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
- ios中的三种弹框《转》
目前为止,已经知道3种IOS弹框: 1.系统弹框-底部弹框 UIActionSheet (1)用法:处理用户非常危险的操作,比如注销系统等 (2)举例: UIActionSheet *sheet = ...
- ios中的三种弹框
目前为止,已经知道3种IOS弹框: 1.系统弹框-底部弹框 UIActionSheet (1)用法:处理用户非常危险的操作,比如注销系统等 (2)举例: UIActionSheet *sheet = ...
- swift4.2 - 一个自定义view弹框
import UIKit /* * 注册协议view:没找到 UI原图,咱不实现 */ class JYRegisterProtocolView: UIView { /// 点击同意协议的回调 pri ...
- iOS 15 无法弹出授权弹框之解决方案---Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.0
2021年9月30日下午:我正愉快的期盼着即将到来的国庆假期,时不时刷新下appstoreconnect的网址,28号就提上去的包,今天还在审核中....由于这个版本刚升级的xcode系统和新出的iO ...
- iOS 可高度自定义的底部弹框
技术: iOS Objective-C 概述 一个可以让开发者通过编写 tableView 的内容随心所欲的定制自己想要的底部弹框 详细 代码下载:http://www.demodashi.com ...
- IOS8 UIAlertController 弹框
本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/35551769 IOS8中,Apple将UIActionSheet和UIAlertVi ...
随机推荐
- yum安装zabbix故障报错
装zabbix时报错 [root@zabbix ~]# rpm -ivh zabbix-server-mysql-2.2.3-1.el6.x86_64.rpm zabbix-web-mysql-2.2 ...
- spring aop execution用法
代码结构: 1. "execution(* com.ebc..*.*(..))" 与 "execution(* com.ebc..*(..))" 2019-0 ...
- spring boot 启动时运行代码(2)ApplicationListener
项目概览: StepExecutor: @Component @Slf4j public class StepExecutor implements Runnable { @Autowired pri ...
- Selenium2(WebDriver)中执行JavaScript代码 (转)
在用selenium编写web页面的自动化测试代码时,可能需要执行一些JavaScript代码,selenium本身就支持执行js,我们在代码中可以使用executeScript.executeAsy ...
- 卸载3DSMAX
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- Animation 把动画片段拖入Animation组件里后不能播放
1. 选中动画片段,点击右上角三道横杠那个按钮,选择Debug: 2.选择Legacy,然后再点击那个三道横岗的按钮,选择Normal就可以用了应该.
- [转]how can I change default errormessage for invalid price
本文转自:http://forums.asp.net/t/1598262.aspx?how+can+I+change+default+errormessage+for+invalid+price I ...
- PyCharm5 破解汉化
作者博文地址:https://www.cnblogs.com/liu-shuai/ 破解: 将下列序列号复制到软件激活界面即可破解. 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0 ...
- (转)shell中test命令方法详解
test命令用法.功能:检查文件和比较值 shell中test命令方法详解 原文:https://www.cnblogs.com/guanyf/p/7553940.html 1)判断表达式 if te ...
- WEB服务器、网站、域名、IP地址、DNS服务器之间的关系
域名首先指向你的服务器,这个过程叫解析. 服务器分成好多小块,每小块叫一个空间或者一个虚拟主机. 所以当你输入你的域名以后,服务器收到你域名的访问信息,但不知道要打开这么多个小块中的那一个.所以要 ...