无法从模型中获取描述以覆盖和显示

时间:2013-10-12 02:48:18

标签: iphone ios objective-c

我有这个在另一个应用程序工作就好了,完全相同的代码,一切都在故事板中链接?我不知道发生了什么事。似乎assignInfo.className字符串保持为nul。并且描述方法也是零。看看:

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

1 个答案:

答案 0 :(得分:0)

之前我说错了:

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


}

后:

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


}

只是一个愚蠢的错误。