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 ...
随机推荐
- python3 发送邮件添加附件
from email.header import Headerfrom email.mime.application import MIMEApplicationfrom email.mime.mul ...
- 阿里插件检查 lombok报错---方法缺少 '@Override' 注解
问题: Eclipse里,阿里编码规约插件扫描代码出现,但是idea却没有. 解决: 将以上注解改成 @Setter @Getter @NoArgsConstructor @AllArgsConstr ...
- Linux安装Sqlmap等工具
简单记录一下安装过程,都是小白教程,省的哪天又忘了要去百度. 1.下载sqlmap 源码进行安装 wget https://github.com/sqlmapproject/sqlmap/tarbal ...
- 2----scrapy框架之代理and日志级和请求传参
一.代理 爬虫文件 daili.py class DailiSpider(scrapy.Spider): name = 'daili' #allowed_domains = ['www.xxx.com ...
- Django media的设置
django在定义模型时需要一些上传的文件,例如图片 class Banner(models.Model): """ 轮播图models titles 标题 images ...
- Jenkins遇到哪些坑~
1Jenkins关闭和重启实现方式. 1.关闭Jenkins 只需要在访问jenkins服务器的网址url地址后加上exit.例如我jenkins的地址http://localhost:8080/ ...
- ExtJS 开发总结
1. ExtJS的定位是RIA,和Prototype.jQuery等类库的定位不同.使用ExtJS做开发,就是意味着以客户端开发为主,不然就不叫RIA框架了,而Prototype.jQuery等只是辅 ...
- Win10磁盘占用率过高
打开服务 禁用Superfetch 禁用Windows Search 禁用Connected User Experiences and Telemetry 禁用Windows Update[恢复选项卡 ...
- 移动端的click点透问题
在移动端开发中,有时会出现click点透的问题. 一.什么是click点透 以下情况,在B元素上有半透明红色遮盖层A,黄色B元素内有可点击链接C. tips:以下举例仅针对webkit内核浏览器,所有 ...
- 3d Max 2014安装失败怎样卸载3dsmax?错误提示某些产品无法安装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...