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