-2

我需要能够在警报中显示开关是打开还是关闭以及其他详细信息,所有详细信息都显示得很好,但是当我尝试添加 notificationStatus 字符串时,它给了我一个错误。“使用未声明的标识符‘notificationStatus’”

-(void) procrastinationNotificationSwitchOnOrOff {

    if (_procrastinationNotificationSwitch.on) {
        _notificationOnOffLabel.text = @"Procrastination Notification On";
        NSString *notificationStatus = @"NOTIFICATION ON";
        NSLog(notificationStatus);
    }
    else {
        _notificationOnOffLabel.text = @"Procrastination Notification Off";
        NSString *notificationStatus = @"NOTIFICATION OFF";
        NSLog(notificationStatus);
    }
}


-(void) presentMessage:(NSString *)message {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Class Stuff" message:message delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [alert show];

}

-(void) notificationStatus:(NSString *)stat {
   NSString *status = [NSString stringWithFormat:@"%@", stat];

}


-(IBAction)returnKeyButton:(id)sender {
    [sender resignFirstResponder];

    NSString *classNameString = self.className.text;
    NSLog(classNameString);
    NSString *assignmentTitleString = self.assignmentTitle.text;
    NSLog(assignmentTitleString);
    NSString *assignmentDescriptionString = self.assignmentDescription.text;
    NSLog(assignmentDescriptionString);
    NSString *totalStrings = [NSString stringWithFormat:@"%@ %@ %@ %@", classNameString, assignmentTitleString, assignmentDescriptionString, notificationStatus];
    NSLog(totalStrings);

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateStyle = NSDateFormatterShortStyle;

    NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date];
    NSLog(@"Alarm Set Button Tapped : %@", dateTimeString );
    [self presentMessage:totalStrings];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [_procrastinationNotificationSwitch addTarget:self action:@selector(procrastinationNotificationSwitchOnOrOff) forControlEvents:UIControlEventValueChanged];
}
4

2 回答 2

0

您的方法 procrastinationNotificationSwitchOnOrOff 中有一个局部变量 notificationStatus。你也有通知状态。您没有属性或实例变量 notificationStatus。

添加属性通知状态。摆脱方法notificationStatus。始终使用 self.notificationStatus 读取和写入 notificationStatus。问题解决了。

于 2013-09-22T23:51:17.433 回答
0

我认为您使用该方法会使事情变得混乱

-(void) notificationStatus:(NSString *)stat {
   NSString *status = [NSString stringWithFormat:@"%@", stat];

}

最好将其设为局部变量,如果您想操作它,请使用 getter 和 setter。

于 2013-09-22T23:52:02.503 回答