2
我有三个UITextFields,我需要第一个标签到第二个时候点击下一个,第二个标签到第三个时候点击下一个。最后第三个隐藏键盘。作为一个侧面的问题,用户可以通过点击所有文本字段上的任何其他位置来隐藏键盘?下一步按钮将焦点带到下一个UITextField?
这里是我的代码:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
-(void) procrastinationNotificationSwitchOnOrOff {
if (_procrastinationNotificationSwitch.on) {
_notificationOnOffLabel.text = @"Procrastination Notification On";
self.notificationStatus = @"NOTIFICATION ON";
NSLog(self.notificationStatus);
}
else {
_notificationOnOffLabel.text = @"Procrastination Notification Off";
self.notificationStatus = @"NOTIFICATION OFF";
NSLog(self.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)addButton:(id)sender {
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);
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:@"Class Name: %@\r Assignment Title: %@ \rAssignment Description: %@ \rDue: %@ \r%@", classNameString, assignmentTitleString, assignmentDescriptionString, dateTimeString, self.notificationStatus];
NSLog(totalStrings);
[self presentMessage:totalStrings];
}
-(IBAction)returnKeyButton:(id)sender {
[sender resignFirstResponder];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_procrastinationNotificationSwitch addTarget:self action:@selector(procrastinationNotificationSwitchOnOrOff) forControlEvents:UIControlEventValueChanged];
self.notificationStatus = @"NOTIFICATION OFF";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
当你说把它放在某个地方,你的意思是什么。我是一名初学者。 – AbdelElrafa
它可以在你的'UIViewController'的'viewDidLoad'方法中。我编辑了asnwer,详细说明了一点点 –
它说dismissKeyboard是未使用的,即使我完全按照你所说的去做了吗? – AbdelElrafa