1

私はこれを別のアプリでうまく動作させていますが、まったく同じコードで、すべてがストーリーボードにリンクされていますか? 何が起こっているのかわかりません。assignmentInfo.className 文字列がヌルに保たれているようです。また、記述方法もヌルです。見てみましょう:

AddEditViewController.h -

{
    IBOutlet UIDatePicker *dateTimePicker;
}

@property (nonatomic, strong) IBOutlet UITextField *className;
@property (nonatomic, strong) IBOutlet UITextField *assignmentTitle;
@property (nonatomic, strong) IBOutlet UITextField *assignmentDescription;
@property (nonatomic, strong) IBOutlet UISwitch *procrastinationNotificationSwitch;
@property (nonatomic,strong)AssignmentInfo *assignmentInfo;
- (IBAction)addTheInfo:(id)sender;

AddEditViewController.m -

{
    if (!_assignmentInfo) {
        _assignmentInfo = [[AssignmentInfo alloc]init];
    }
    return _assignmentInfo;


}

- (IBAction)addTheInfo:(id)sender {

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateStyle = NSDateFormatterShortStyle;
    NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date];
    self.assignmentInfo.className = self.className.text;
    self.assignmentInfo.assignmentTitle = self.assignmentTitle.text;
    self.assignmentInfo.assignmentDescription = self.assignmentDescription.text;
    self.assignmentInfo.dateTimeString = dateTimeString;
    NSLog(@"%@",self.assignmentInfo.className);    
    NSLog(@"%@",self.assignmentInfo.description);

    [self presentMessage:self.assignmentInfo.description];



}

AssignmentInfo.h -

@property (nonatomic,strong)NSString *className;
@property (nonatomic,strong)NSString *assignmentDescription;
@property (nonatomic,strong)NSString *assignmentTitle;
@property (nonatomic,strong)NSString *dateTimeString;

@property (nonatomic)bool notifcationStatus;

AssignmentInfo.m -

-(NSString *)description
{

    return [NSString stringWithFormat:@"Class: %@\r Assignment Title: %@ \rAssignment Description: %@ \rDue: %@ \r%s", self.className, self.assignmentTitle, self.assignmentDescription, self.dateTimeString,self.notifcationStatus ? "Notification On" : "Notification Off"];
}
4

1 に答える 1

0

以前は間違っていました:

-(AssignmentInfo *)classObject
{
    if (!_assignmentInfo) {
        _assignmentInfo = [[AssignmentInfo alloc]init];
    }
    return _assignmentInfo;


}

後:

-(AssignmentInfo *)assignmentInfo
{
    if (!_assignmentInfo) {
        _assignmentInfo = [[AssignmentInfo alloc]init];
    }
    return _assignmentInfo;


}

ばかげた間違いです。

于 2013-10-12T03:07:01.853 に答える