UIActionSheet+UIToolBar+UIDatePickerView
来源:互联网 发布:淘宝天猫评价采集 编辑:程序博客网 时间:2024/06/05 15:12
//日期弹窗视图
@interface WalletDateActionView : WalletActionView{
NSDate *actionDate;
NSDate *actionMaxDate;
NSDate *actionMinDate;
id <WalletDateActionViewDelegate> delegate;
@private
UIToolbar *_topBar;
UIActionSheet *_action;
UIDatePicker *_picker;
}
//选中日期
@property (nonatomic, retain) NSDate *actionDate;
//最大日期
@property (nonatomic, retain) NSDate *actionMaxDate;
//最小日期
@property (nonatomic, retain) NSDate *actionMinDate;
//Delegate
@property (nonatomic, assign) id <WalletDateActionViewDelegate> delegate;
//弹出视图
- (void)showInView:(UIViewController *)aViewController;//modify by mgqx
//撤销视图
- (void)dismiss;
@end
@protocol WalletDateActionViewDelegate <NSObject>
@optional
//确定提交日期
- (void)dateAction:(WalletDateActionView *)dateAction submitWithDate:(NSDate *)date;
@end
////////////////////
@implementation WalletDateActionView
@synthesize actionDate;
@synthesize actionMaxDate;
@synthesize actionMinDate;
@synthesize delegate;
- (id)init{
if (self = [super init]) {
NSString *title = @"\n\n\n\n\n\n\n\n\n\n\n\n\n";
_action = [[UIActionSheet alloc] initWithTitle:title delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
self.frame = CGRectMake(0, 0, 320, 260);
_topBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
_topBar.barStyle = UIBarStyleBlack;
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleBordered target:self action:@selector(dismiss)];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(submit)];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSMutableArray *items = [NSMutableArray arrayWithObjects:cancelItem, spaceItem, doneItem, nil];
_topBar.items = items;
[self addSubview:_topBar];
_picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
_picker.datePickerMode = UIDatePickerModeDate;
[self addSubview:_picker];
[_action addSubview:self];
[self release];//add by mgq
[doneItem release];
[spaceItem release];
[cancelItem release];
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
if (self.actionBarColor) {
[_topBar setTintColor:self.actionBarColor];
}
if (self.actionDate) {
[_picker setDate:self.actionDate animated:YES];
}
if (self.actionMaxDate) {
[_picker setMaximumDate:self.actionMaxDate];
}
if (self.actionMinDate) {
[_picker setMinimumDate:self.actionMinDate];
}
}
- (void)dealloc{
[actionDate release], actionDate = nil;
[actionMaxDate release], actionMaxDate = nil;
[actionMinDate release], actionMinDate = nil;
//NSInteger count1 = [self retainCount];
[_topBar release], _topBar = nil;
[_picker release], _picker = nil;
if ([[[UIDevice currentDevice] systemVersion] compare:@"5.0"] == NSOrderedAscending)
{
[self retain];
}
[_action release], _action = nil;
NSInteger count = [self retainCount];
[super dealloc];
}
#pragma mark - Public
- (void)showInView:(UIViewController *)aViewController{
[_action showFromTabBar:aViewController.tabBarController.tabBar];
}
- (void)dismiss{
[_action dismissWithClickedButtonIndex:0 animated:YES];
}
- (void)setActionDate:(NSDate *)nActionDate{
if (nActionDate != actionDate) {
[actionDate release];
actionDate = [nActionDate retain];
[_picker setDate:actionDate animated:YES];
}
}
#pragma mark - Private
- (void)submit{
//修改当前日期
actionDate = _picker.date;
//协议存在
if (self.delegate) {
//委托对象已实现该方法
if ([self.delegate respondsToSelector:@selector(dateAction:submitWithDate:)]) {
//调用委托方法
[self.delegate dateAction:self submitWithDate:self.actionDate];
}
}
[self dismiss];
}
@end
///////////////
#import "WalletActionView.h"
@implementation WalletActionView
@synthesize actionBarColor;
- (id)init{
self = [super init];
if (self) {
self.actionBarColor = [UIColor blackColor];
}
return self;
}
- (void)dealloc{
[actionBarColor release];
[super dealloc];
}
- UIActionSheet+UIToolBar+UIDatePickerView
- iOS 之UIActionSheet+UIToolBar+UIDatePickerView
- UIToolBar
- UIToolbar
- UIToolbar
- UIToolbar
- UIToolbar
- UIToolBar
- UIToolbar
- UIToolBar
- UIToolbar
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- 转自:MoreWindows 秒杀多线程
- ACE_Get_Opt解析命令行
- C语言面试之——地址的强制转换
- Linux时间管理 (二)
- pl/sql学习7——pl/sql记录表
- UIActionSheet+UIToolBar+UIDatePickerView
- NEMA-0183(GPRMC GPGGA)详细解释
- 2012 Multi-University Training Contest 3:Arcane Numbers 1
- 无法启动程序“%CSIDL_PROGRAM_FILES%\XX\XX.exe”。发生了通常表示安装被损坏的错误(代码 0x8007007e)。
- Drools5核心类图
- RAID 10与RAID 0+1有什么区别?
- Javascript继承
- POJ 1094(拓扑排序)
- Android编译错误处理 make ......./noproguard.classes-with-local.dex] 已杀死