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 ...
随机推荐
- pandas之美国2012年总统候选人政治献金数据分析
- Tomcat故障
1.1 故障日志 31-May-2018 16:11:41.136 INFO [http-nio-8017-exec-5] org.apache.coyote.http11.AbstractHttp1 ...
- source vs export AND ctrl d vs ctrl z
在脚本中export,只在当前shell脚本进程和子进程中有效 source的作用中是将export的变量在当前脚本环境生效, 如果是在父脚本中执行source,在子脚本中执行export, 父脚本退 ...
- vue(2)创建项目
1.创建项目 cmd到自己指定目录下,执行 vue init webpack-simple hello-vue 2.安装项目依赖 cd hello-vue cnpm install 3.运行该项目,测 ...
- sort命令和对中文的处理
使用示例:sort -k1,1nr xxxfile 需要指定起始列和结束列,否则可能排序错误 sort命令应用于中文时需要在sort前设置环境变量(以兼容C语言的标准): LC_COLLATE=C ...
- Java基础05-运算符
1.赋值运算符:= 2.算术运算符: (1)一元运算符: i++;先使用后自身加1 int i=1;int b=i+1; b=1 i=2 ++i;先对自身加1后使用 int j=1;int b=+ ...
- 模拟登陆并爬取Github
因为崔前辈给出的代码运行有误,略作修改和简化了. 书上例题,不做介绍. import requests from lxml import etree class Login(object): def ...
- EditPlus编写PHP使用技巧
1,建立php模板 方法:在EditPlus的文件目录下,新建template.php文件,写入<?php ?>内容保存,再在editplus的模板中 载入应用即可. 2,建立函数自动补齐 ...
- SSH密钥登录原理
Client 发送请求 login 请求 --> Server 接受请求 --> 根据 authorized_key 文件中的对应 Client 的 ip 地址的公钥对一串随机数进行加密 ...
- 一个ActionResult中定位到两个视图—<团委项目>
在使用MVC做项目的时候一般的情况就是一个ActionResult一个视图,这样对应的Return View();就可以找到下面对应的视图,这是根据一个原则,“约定大于配置”,但是我们有的时候需要在一 ...