选择日期范围,同时要判断选择的开始日期和结束日期的选择是否正确

选择日期范围,同时要判断选择的开始日期和结束日期的选择是否正确

//将字符串转为日期,为下一步比较

- (NSDate*)stringToDate: (NSString*)string

{

    NSDateFormatter* dateFormatter = [ [ NSDateFormatter alloc ] init ];

    [ dateFormatter setDateFormat: @"yyyy-MM-dd" ];

    NSDate* date = [ dateFormatter dateFromString: string ];

//        NSLog( @"date %@" , date );

    [ dateFormatter release ];

    return date;

}

//++++++++++++++++++++++++查找按钮等方法++++++++++++++++++++++++++++++++++++//

//点击查找按钮后

- (void)searchMessage 

{

    //================ 先隐藏未隐藏的时间选择器 =====================//

    [ UIView beginAnimations: nil context: nil ];

    [ UIView setAnimationDuration: 0.3 ];

    //隐藏工具条

    CGRect toolbarFrame = self.navigationController.toolbar.frame;

    toolbarFrame.origin.y = 

    self.view.bounds.size.height + 65 ;

    self.navigationController.toolbar.frame = toolbarFrame;

    //隐藏完成按钮

    UIBarButtonItem* spaceButton = [ [ [ UIBarButtonItem alloc ] 

                                      initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace

                                      target: nil action: nil ] autorelease ];

    [ self setToolbarItems: [ NSArray arrayWithObject: spaceButton ] animated: YES ];

    //隐藏日期选择器

    datePicker_.frame = toolbarFrame;

    [ UIView commitAnimations ];

    //==========================================================//

    

    

    if ( [ beginDateTextField_.text length ] && [ endDateTextField_.text length ] ) 

    {

        

        //********** 时间比较 *************************//

        

        NSDate* beginDate = [ self stringToDate: beginDateTextField_.text ];

        NSDate* endDate = [ self stringToDate: endDateTextField_.text ];

        //如果开始日期比结束日期前的话,才执行下一步,否则显示警告框

        if ( NSOrderedAscending == [ beginDate compare: endDate ] )

        {

            //执行下一步

............

         }

         else  //日期范围错误

         {

             UIAlertView* errorAlert = [ [ UIAlertView alloc ] initWithTitle: @"选择日期范围错误" message: @"请选择正确日期范围" delegate: self cancelButtonTitle: @"确定" otherButtonTitles: nil , nil ];

             [ errorAlert show ];

             [ errorAlert release ];

         }

        //*******************************************//

    }

    else      //未选择日期范围,存在未选日期

    {

        UIAlertView* errorAlert = [ [ UIAlertView alloc ] initWithTitle: @"未选择日期范围" message: @"请选择日期范围" delegate: self cancelButtonTitle: @"确定" otherButtonTitles: nil , nil ];

        [ errorAlert show ];

        [ errorAlert release ];

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值