我有UIDatepicker
,它在iOS7中随机崩溃。在模拟器中,UIDatepicker
完美地工作,但在真实设备上总是崩溃。错误是EXC_BAD_ADRESS
,但Xcode没有给我更多信息。
请帮助我!
我的代码是:
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 :(得分:0)
@property (nonatomic, strong) IBOutlet UIDatePicker *datePicker;
当其他oultest是strong
时,为什么retain
。您正在使用ARC还是什么?
如果你使用ARC,那么所有oultes都要strong
,如果不是retain
。
如果你使用插座,你不需要分配它:{{1}}
在任何地方使用datePicker = [[UIDatePicker alloc]init];
代替seld.datePicker
。
datePicker
UIDatePicker *datePicker;
@interface VistaRuedaViewController ...{ }
和formatter