我需要能够在警报中显示开关是否打开以及其他详细信息,所有细节都显示正常但是当我尝试添加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];
}
答案 0 :(得分:0)
您的方法procrastinationNotificationSwitchOnOrOff中有一个局部变量notificationStatus。您还有notificationStatus。您没有属性或实例变量notificationStatus。
添加属性notificationStatus。摆脱方法notificationStatus。始终使用self.notificationStatus读取和写入notificationStatus。问题解决了。
答案 1 :(得分:0)
我认为通过使用方法
让你感到困惑-(void) notificationStatus:(NSString *)stat {
NSString *status = [NSString stringWithFormat:@"%@", stat];
}
最好将它变成局部变量,如果你想操纵它,可以使用getter和setter。