简体   繁体   English

ios datepicker随机崩溃

[英]ios datepicker crashes randomly

I have a UIDatepicker and it crashes randomly in iOS7. 我有一个UIDatepicker ,它在iOS7中随机崩溃。 At the simulator, the UIDatepicker works perfectly but on the real device always crash. 在模拟器上, UIDatepicker可以完美运行,但在实际设备上始终会崩溃。 The error is EXC_BAD_ADRESS but the Xcode doesn't give me more information. 错误是EXC_BAD_ADRESS但Xcode没有给我更多信息。

Please help me! 请帮我!

My code is: 我的代码是:

VistaRuedaViewController.h VistaRuedaViewController.h

@interface VistaRuedaViewController : UIViewController <UITableViewDataSource, UITableViewDelegate,UITabBarControllerDelegate, UITabBarDelegate>
{

    NSString *fecha;
    Utilidades *util;
    BOOL conexion;
    UIDatePicker *datePicker;
}

@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) IBOutlet UITableView *table;
@property (nonatomic, strong) IBOutlet UIDatePicker *datePicker;

@property (nonatomic, retain) IBOutlet UILabel *labelAviso;

@property (nonatomic, retain) IBOutlet UITabBar *tabbar;

-(IBAction)SelectSend:(id)sender;

@end

VistaRuedaViewController.m VistaRuedaViewController.m

- (void)viewDidLoad
{
    ...

    datePicker = [[UIDatePicker alloc]init];
    [datePicker setDate:[NSDate date]];
    self.datePicker.minimumDate = [NSDate date]; 
    datePicker.datePickerMode = UIDatePickerModeDate;

    ...
}

    -(IBAction)SelectSend:(id)sender{
        UIDatePicker *dp = (UIDatePicker *) sender;

        //[table reloadData];
        NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
        [formatter setLocale:[NSLocale currentLocale]];
        [formatter setDateFormat:@"dd/MM/yyyy"];
        fecha =[formatter stringFromDate:dp.date];
        NSLog(@"FECHA DATAPICKER: %@", dp.date);

        NSString *idioma;
        NSString *currentL = [Global sharedMySingleton].test;
        if([currentL isEqualToString:@"ca-ES"]){
            idioma = @"ca";
        }
        else
        {
            idioma = currentL;
        }
        button.enabled = NO;
        NSString *PlaningURLString = [NSString stringWithFormat:@"%@%@/PlaningHorario", NSLocalizedString(@"protocolo", @""), NSLocalizedString(@"servidor", @"")];

        util = [[Utilidades alloc]init];
        conexion = [util testInternetConnection];

        if (conexion) {
            Planing_pasarela *cargaPlaning = [[Planing_pasarela alloc] init];
            [cargaPlaning NSURLConnectionFunction:PlaningURLString:fecha:fecha:idioma];

            int ret =[cargaPlaning comprobarFlag];

            button.enabled = YES;

            if (ret==1) {
                [table reloadData];
                NSLog(@"DATAPICKER: %@", fecha);
            }else{
            // Usuario y token incorrectos

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:AMLocalizedString(@"logoutAlert", @"") message:AMLocalizedString(@"logout", @"") delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                alert.tag = 1;
                [alert show];
            }
        }

    }

Thank you for advance. 谢谢您的提前。

  1. @property (nonatomic, strong) IBOutlet UIDatePicker *datePicker; Why it's strong when other oultest is retain . retain其他最不利条件时,为什么它那么strong You are using ARC or what? 您正在使用ARC还是什么? If you use ARC, than all oultets shold be strong , if not then retain . 如果您使用ARC,则比所有双峰更strong ,如果没有,则retain

  2. And if you use outlet, you don't need allocate it: datePicker = [[UIDatePicker alloc]init]; 而且,如果您使用插座,则无需分配它: datePicker = [[UIDatePicker alloc]init];

  3. Use everywhere seld.datePicker instead datePicker . 在各处使用seld.datePicker而不是datePicker

  4. You don't need UIDatePicker *datePicker; 您不需要UIDatePicker *datePicker; inside @interface VistaRuedaViewController ...{ } @interface VistaRuedaViewController ...{ }内部@interface VistaRuedaViewController ...{ }
  5. If App is non-ARC, then you need release formatter and util 如果应用程序是非ARC,则需要发布formatterutil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM