2014-01-14 163 views
1

我有一個UIDatepicker它在iOS7中隨機崩潰。在模擬器上,UIDatepicker完美工作,但在真實設備上總是崩潰。錯誤是EXC_BAD_ADRESS,但Xcode並沒有給我更多的信息。ios datepicker隨機崩潰

請幫幫我!

我的代碼是:

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

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

    } 

感謝您提前。

+0

在哪一行'壞access'? –

+0

我不知道該行,Xcode只顯示了我:EXC_BAD_ACCESS(code = 1,address = 0xa00000004) – amurcia

+0

添加一個異常斷點。這可能會幫助您顯示發生崩潰的確切位置。 – Abhinit

回答

0
  1. @property (nonatomic, strong) IBOutlet UIDatePicker *datePicker; 爲什麼它的strong當其他oultest是retain。你正在使用ARC還是什麼? 如果您使用ARC,則比所有oultets都要低,如果不是retain,則爲strong

  2. 而且如果你用插座,你不需要它分配:datePicker = [[UIDatePicker alloc]init];

  3. 到處使用seld.datePicker代替datePicker

  4. 你不需要UIDatePicker *datePicker;@interface VistaRuedaViewController ...{ }
  5. 如果應用程序是不ARC,那麼你需要釋放formatterutil
+0

我做了3個步驟,但問題仍然存在... – amurcia

+0

現在的錯誤是不同的:EXC_BAD_INSTRUCTION(code = EXC_ARM_UNDEFINED,subcode = 0xffffffc) – amurcia

+0

我釋放datePicker裏面{}和util(問題仍在發生),但爲什麼我需要釋放格式化程序? – amurcia