iOS 之UIActionSheet+UIToolBar+UIDatePickerView

本文介绍了一个自定义的iOS日期选择器视图组件,该组件使用UIKit框架实现,包括日期选择器、顶部工具栏及按钮等元素。通过设置最大最小日期限制与委托方法,可以轻松集成到应用中。
//日期弹窗视图
@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];
}

【故障诊断】【pytorch】基于CNN-LSTM故障分类的轴承故障诊断研究[西储大学数据](Python代码实现)内容概要:本文介绍了基于CNN-LSTM神经网络模型的轴承故障分类方法,利用PyTorch框架实现,采用西储大学(Case Western Reserve University)公开的轴承故障数据集进行实验验证。该方法结合卷积神经网络(CNN)强大的特征提取能力和长短期记忆网络(LSTM)对时序数据的建模优势,实现对轴承不同故障类型和严重程度的高精度分类。文中详细阐述了数据预处理、模型构建、训练流程及结果分析过程,并提供了完整的Python代码实现,属于典型的工业设备故障诊断领域深度学习应用研究。; 适合人群:具备Python编程基础和深度学习基础知识的高校学生、科研人员及工业界从事设备状态监测与故障诊断的工程师,尤其适合正在开展相关课题研究或希望复现EI级别论文成果的研究者。; 使用场景及目标:① 学习如何使用PyTorch搭建CNN-LSTM混合模型进行时间序列分类;② 掌握轴承振动信号的预处理与特征学习方法;③ 复现并改进基于公开数据集的故障诊断模型,用于学术论文撰写或实际工业场景验证; 阅读建议:建议读者结合提供的代码逐行理解模型实现细节,重点关注数据加载、滑动窗口处理、网络结构设计及训练策略部分,鼓励在原有基础上尝试不同的网络结构或优化算法以提升分类性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值