@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];
}