自定义带有uitableview的alertview对话框
#import <UIKit/UIKit.h>
typedef void(^MyCompleteHandler) (NSString *selectString);
@interface TJCustomAlertViewOrTableView : UIView
{
MyCompleteHandler completeHandler;
}
@property(nonatomic,strong)NSMutableArray *dataSoureArray;
+(TJCustomAlertViewOrTableView *)shareInStance;
+(void)showAlertViewOrTableViewandCompleteHandler:(MyCompleteHandler)myCompleteHander;
-(void)showAlertViewOrTableViewandCompleteHandler:(MyCompleteHandler)myCompleteHander; @end
#import "TJCustomAlertViewOrTableView.h"
#define kcontentViewSize CGSizeMake(200.0f, 250.0f);
@interface TJCustomAlertViewOrTableView ()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate>
{
UITableView *myTableView;
UIView *contentView;
UIButton *okBtn;
NSInteger selectRow;
}
@end @implementation TJCustomAlertViewOrTableView
+(TJCustomAlertViewOrTableView*)shareInStance
{
static TJCustomAlertViewOrTableView *customAlertViewOrTableView;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ customAlertViewOrTableView=[[TJCustomAlertViewOrTableView alloc]init];
});
return customAlertViewOrTableView; }
-(instancetype)init
{
if (self=[super init]) {
[self setUp];
}
return self;
}
-(void)setUp
{
self.backgroundColor=[UIColor colorWithRed: green: blue: alpha:0.5f];
self.frame=[UIScreen mainScreen].bounds;
CGRect frect=CGRectZero;
frect.size=kcontentViewSize;
frect.origin.x=[UIScreen mainScreen].bounds.size.width/4.0f;
frect.origin.y=[UIScreen mainScreen].bounds.size.height/4.0f; contentView=[[UIView alloc]initWithFrame:frect];
contentView.backgroundColor=[UIColor whiteColor];
contentView.layer.masksToBounds=YES;
contentView.layer.cornerRadius=8.0f;
[self addSubview:contentView];
UITapGestureRecognizer *tapBackGround=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissAlertViewOrTableView:)];
tapBackGround.delegate=self;
[self addGestureRecognizer:tapBackGround]; okBtn=[UIButton buttonWithType:UIButtonTypeCustom];
okBtn.translatesAutoresizingMaskIntoConstraints=NO;
[okBtn setTitle:@"确定" forState:UIControlStateNormal];
[okBtn addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
[okBtn setBackgroundColor:[UIColor redColor]];
[contentView addSubview:okBtn];
NSArray *constraint_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[okBtn]-5-|" options: metrics:nil views:NSDictionaryOfVariableBindings(okBtn)];
NSArray *constraint_V=[NSLayoutConstraint constraintsWithVisualFormat:@"V:[okBtn(44)]-5-|" options: metrics:nil views:NSDictionaryOfVariableBindings(okBtn)]; [contentView addConstraints:constraint_H];
[contentView addConstraints:constraint_V]; myTableView=[[UITableView alloc]init];
myTableView.translatesAutoresizingMaskIntoConstraints=NO;
myTableView.delegate=self;
myTableView.dataSource=self;
[contentView addSubview:myTableView]; NSArray *tableView_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[myTableView]-0-|" options: metrics:nil views:NSDictionaryOfVariableBindings(myTableView,okBtn)]; NSArray *tableView_V=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[myTableView]-49-|" options: metrics:nil views:NSDictionaryOfVariableBindings(myTableView,okBtn)];
[contentView addConstraints:tableView_H];
[contentView addConstraints:tableView_V]; }
-(void)dismissView:(UIButton *)sender
{
if (completeHandler)
{
completeHandler(_dataSoureArray[selectRow]);
}
[self hideView]; }
-(void)dismissAlertViewOrTableView:(UITapGestureRecognizer *)tapGesture
{
CGPoint point=[tapGesture locationInView:self];
if (!CGRectContainsPoint(myTableView.frame, point)) {
[self hideView];
} }
-(void)showView
{
UIWindow *keyWindow=[UIApplication sharedApplication].keyWindow;
[keyWindow addSubview:self];
contentView.alpha=;
contentView.transform=CGAffineTransformMakeScale(0.01f, 0.01f);
[UIView animateWithDuration:0.3f animations:^{
contentView.alpha=1.0f;
contentView.transform=CGAffineTransformMakeScale(1.0f, 1.0f); }];
}
-(void)hideView
{
[UIView animateWithDuration:0.3f animations:^{ contentView.alpha=;
contentView.transform=CGAffineTransformMakeScale(0.01f, 0.01f);
} completion:^(BOOL finished) { [self removeFromSuperview];
}];
} +(void)showAlertViewOrTableViewandCompleteHandler:(MyCompleteHandler)myCompleteHander
{
[[TJCustomAlertViewOrTableView shareInStance] showAlertViewOrTableViewandCompleteHandler:myCompleteHander]; }
-(void)showAlertViewOrTableViewandCompleteHandler:(MyCompleteHandler)myCompleteHander
{
completeHandler=myCompleteHander;
[self showView];
} #pragma mark -UITableViewDataSource or UITableViewDelegate -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataSoureArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.textLabel.text=_dataSoureArray[indexPath.row];
return cell; }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44.0f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectRow=indexPath.row;
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if(touch.view==myTableView)
{
return YES;
}
return NO; }
@end #import "ViewController.h"
#import "TJCustomAlertViewOrTableView.h"
@interface ViewController ()
{
NSMutableArray *dataArray;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
dataArray=[NSMutableArray array];
for (int i=; i<; i++) {
[dataArray addObject:[NSString stringWithFormat:@"test%d",i]];
}
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)showViewBtnClick:(UIButton *)sender
{
[TJCustomAlertViewOrTableView shareInStance].dataSoureArray=dataArray;
// [[TJCustomAlertViewOrTableView shareInStance]showAlertViewOrTableViewandCompleteHandler:^(NSString *selectString) {
//
// NSLog(@"selectString=%@",selectString);
// }]; [TJCustomAlertViewOrTableView showAlertViewOrTableViewandCompleteHandler:^(NSString *selectString) { NSLog(@"selectString=%@",selectString);
}]; } @end

自定义带有uitableview的alertview对话框的更多相关文章
- 雷林鹏分享:jQuery EasyUI 窗口 - 自定义带有工具条和按钮的对话框
jQuery EasyUI 窗口 - 自定义带有工具条和按钮的对话框 您可以创建一个带有工具栏(toolbar)和按钮(button)的对话框(dialog),可以从 HTML 标记创建.这个教程描述 ...
- 自定义带有图片的PreferenceActivity
http://my.oschina.net/huangsm/blog/40027 和大家分享一下关于android中PreferenceActivity使用以及为配置信息文件中添加图标的功能,首先给大 ...
- 带有关闭按钮的alertView
概述 由于讨厌系统自带的alertView只能通过点击按钮才能关闭.你说万一按钮区域都是功能性的操作呢(这可不是我胡思乱想哦,要怪就产品的想法吧,呵呵哒),所以我们还是应该备有一个带有“X”(关闭按钮 ...
- iOS开发小技巧--自定义带有占位文字的TextView(两种方式)
自定义控件注意或框架注意:自己暴露在外面的属性,一定要重写setter,保证外界与内部的交互性 一.方案一:通过drawRect:方法将文字画到textView中,监听文字改变用的是通知中心(代理也可 ...
- jQueryWEUI自定义对话框-带有textarea
jQueryWEUI 示例下载 在jQueryWEUI中提供了很多类型的对话框, 可以去访问看一下. 今天记录的则是,自己定义的一个带有文本域的对话框,这样,可以不通过调转页面,实现一些信息的提交. ...
- Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)
前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...
- 安卓 Dialogs(对话框)
转载自:http://www.apkbus.com/home.php?mod=space&uid=679028&do=blog&id=61197 对话框是一个小的窗口用以提示用 ...
- JOptionPane如何自定义按钮绑定事件
JOptionPane如何自定义按钮绑定事件 2018年01月29日 19:27:10 阅读数:475 摘自:https://blog.csdn.net/m0_37355951/article/det ...
- iOS学习31之UITableVIewCell自定义
1. 自定义Cell 1> 为什么要自定义Cell UITableView 中系统的Cell共提供了四种默认样式, 分别是: UITableViewCellStyleDefault UITab ...
随机推荐
- 从今天开始每天刷一题,并写在这里 分类: ACM 2015-06-16 23:52 14人阅读 评论(0) 收藏
开始什么题都可以,后面会加大难度. 每天! 如果有一天有特殊情况,也要来这里打卡,并说明原因,并在其他某一天补上! 版权声明:本文为博主原创文章,未经博主允许不得转载.
- MecAnim
[MecAnim] MecAnim是Unity 4.0推出的新的动画系统,新系统使用Animator组件来控制动画,老系统使用Animation组件来控制动画.此篇讲述MecAnim系统. What ...
- whereis 命令
whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息. 和find相比,whereis查找的速度非 ...
- UVaLive 6609 Meeting Room Arrangement (贪心,区间不相交)
题意:给定 n 个区间,让你选出最多的区间,使得每个区间不相交. 析:贪心题,贪心策略是按右端点排序,然后按着选即可. 代码如下: #pragma comment(linker, "/STA ...
- ODBC 是什么
In computing, ODBC (Open Database Connectivity) is a standard programming language middleware API fo ...
- 读数据库表填充DataTable
我一般用的有2中方法: 1.数据填充 string sqlcmd="select * from table"; SqlDataAdapter adapder = new SqlDa ...
- IP报文解析及基于IP 数据包的洪水攻击
版本(4bit) 报头长度(4bit) 优先级和服务类型(8bit) 总长度(16bit) 标识(16bit) 标志(3bit) 分段偏移(13bit) 存活期(8bit) 协议(8bit) 报头校验 ...
- HTTP原理
HTTP原理 1 简介 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统. HTTP协议的主要特点可概括如下: 1.支持客户/服务器模式. 2.简单快速:客 ...
- 使用IBatisNet的网站,修改database.config无效的问题解决
这周五去客户那更新了一个使用了IBatisNet的Web项目,备份了项目.数据库之后,替换更新的文件(含bin目录)却报数据库连接错. 因为是接手的一个维护项目,加上交接有点问题,所以遇到问题只能自己 ...
- SqlServer数据维护
现有两个表:Code和CodeCategory Code表: CodeCategory表: 现要把Code表中的数据如实维护一份数据,但是要设PlantID字段值为2,而ID要按规则自增并且要与Pla ...