2013-07-30 6 views
1

한 줄의 텍스트 필드에 DatePicker에 문제가 있습니다. 오류가 발생하고 그 이유를 알지 못합니다.텍스트 필드의 날짜 선택기가 작동하지 않습니다.

"@synthesize resDatum;"행의 .mfiele에서 오류가 발생합니다. 오류입니다 : 내가 왜 khnow하지 않는

그리고 resDatum '('있는 NSDate * _strong ')'인스턴스 변수의 유형과 일치하지 않습니다 재산 'resDatum'(을 NSData *) '의 종류 ...

또는 ios6의 텍스트 필드에 DatePicker를 구현하는 더 똑똑한 솔루션이 있습니까? 여기

내 .H : 여기

#import <UIKit/UIKit.h> 
#import <MessageUI/MessageUI.h> 

@interface Reservieren : UIViewController <MFMailComposeViewControllerDelegate> { 

    NSDate *resDatum; 
    UIActionSheet *dateSheet; 

    IBOutlet UITextField *Anzahl; 
    IBOutlet UITextField *Nummer; 
    IBOutlet UISegmentedControl *draussendrinnen; 
    UITextField *Datum;  

    NSString *draussendrinnenstring;  
} 

@property (nonatomic, retain)IBOutlet UITextField *Anzahl; 
@property (nonatomic, retain)IBOutlet UITextField *Nummer; 
@property (nonatomic, retain) NSData *resDatum; 
@property (nonatomic, retain) IBOutlet UITextField *Datum; 

- (void)setDate; 
- (void)dismissDateSet; 
- (void)cancelDateSet; 

- (IBAction)Reservieren_zuruck:(id)sender; 
- (IBAction)textFieldReturn:(id)sender; 
- (IBAction)reservieren:(id)sender; 
- (IBAction)draussendrinnenauswahl:(id)sender; 

@end 

내하는 .m

#import "Reservieren.h" 
#import "ViewController.h" 

@interface Reservieren() 

@end 

@implementation Reservieren 
@synthesize Anzahl, Nummer, Datum; 
@synthesize resDatum; //-->Type of property 'resDatum'(NSData *') does not match type of instance variable 'resDatum'('NSDate *_strong') 

-(void)setDate { 

    //NSLocale *deLocale = [[NSLocale alloc]initWithLocaleIdentifier:@"de_DE"]; 
    dateSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 
    [dateSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 
    CGRect pickerFrame = CGRectMake(0, 44, 0, 0); 
    UIDatePicker *dateDayPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame]; 
    [dateDayPicker setDatePickerMode:UIDatePickerModeDateAndTime]; 

    [dateSheet addSubview:dateDayPicker]; 

    UIToolbar *controlToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, dateSheet.bounds.size.width, 44)]; 

    [controlToolBar setBarStyle:UIBarStyleBlackTranslucent]; 
    [controlToolBar sizeToFit]; 

    UIBarButtonItem *spacer =[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

    UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:@"Auswählen" style:UIBarButtonItemStyleDone target:self action:@selector(dismissDateSet)]; 

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithTitle:@"Abbrechen" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelDateSet)]; 

    [controlToolBar setItems:[NSArray arrayWithObjects:spacer, cancelButton, setButton, nil]animated:NO]; 

    [dateSheet addSubview:controlToolBar]; 
    [dateSheet showInView:self.view]; 
    [dateSheet setBounds:CGRectMake(0, 0, 320, 485)];   
} 


-(void)cancelDateSet {  
    [dateSheet dismissWithClickedButtonIndex:0 animated:YES]; 
} 

- (void)dismissDateSet { 
    NSArray *listOfViews = [dateSheet subviews]; 
    for (UIView *subView in listOfViews) { 
     if([subView isKindOfClass:[UIDatePicker class]]) { 
      self.resDatum = [(UIDatePicker *)subView date]; 
     } 
    }  

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
    [dateFormatter setDateFormat:@"dd.MM.yyyy h.mm"];  
    [Datum setText:[dateFormatter stringFromDate: self.resDatum]];  
    [dateSheet dismissWithClickedButtonIndex:0 animated:YES];  
} 

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    [self setDate]; 
    return NO; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload { 
    [self setDatum:nil]; 
    [super viewDidUnload]; 
} 
@end 
+0

@property (비 원자력, 강력한) NSData * resDatum; , 보유를 쓰지 말라. .. 나에게 그것이 일하고 있냐 지 알게한다!? ?? – NiravPatel

+0

@NiravPatel -'strong'는'retain'의 동의어입니다. 그것들은 ARC 하에서 행동이 동일합니다. –

답변

1

오류는 resDatum 변수 데이터 유형입니다. @property 선언에 NSData 대신 NSDate을 사용하십시오.

지금은 NSDate 대신에 NSData이 필요합니다. NSDate으로 변경하십시오. (이름이 암시처럼) resDatum가 날짜 인 경우

NSDate *resDatum; 
@property (nonatomic, retain) NSData *resDatum; 

변화 :

NSDate *resDatum; 
@property (nonatomic, retain) NSDate *resDatum; 
+1

Ahh이 코드 전체를 보니 감사합니다. 날짜 및 데이터 실수가 표시되지 않습니다.- – Nils

+1

다른 질문 : 오늘 대신에 Heute로 유럽식 포맷 (독일어)으로 DatePicker 포맷을 어떻게 변경할 수 있습니까? – Nils

+0

http://stackoverflow.com/questions/13952063/how-to-change-the-format-of-date-in-date-picker –

0

오류에

NSDate *resDatum; 
@property (nonatomic, retain) NSData *resDatum; 

변경은 부동산 resDatum 전자에서 서로 다른 유형의 변수 resDatum입니다 NSDate (NSData 아님)의 속성 유형. 같은 이름으로 개인 변수를 선언 할 필요가 없습니다 @synthesize 당신은 호텔의 이름이 같은 개인 변수를 필요로하지만, 다른 유형에 사용할 수있는, 그렇지 않은 경우, 사용하는 경우

@synthesize resDatum = _resDatum 
+0

사소한 단점 : 명시 적으로 합성 된 속성에 대한 후행 변수 선언은 OS X의 창 밖으로 나갔습니다. 10.5. backing 변수를 만들지 않고 equals의 오른쪽에있는 이름을 사용하여 원하는 그림자 변수를 선언하십시오. – CodaFi

+0

덕분에 실수를 보지 못했습니다 .-- – Nils

관련 문제