不讲原理。只讲操作。
三 步 :
设置 Text input traits ---》Return key 为DONE
去掉auto-enable Return key 选中状态。
创建一个类为:
@interface BoardReturn : NSObject <UITextFieldDelegate> {
}
@end
@implementation BoardReturn
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
@end
在你的Controller中加入此类
#import "Controller.h"
#import "BoardReturn.h"
@implementation Controller
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
//view上的UIinputfiled 对应的 IBoutlet.
myText.clearButtonMode=UITextFieldViewModeWhileEditing;
myText.delegate=[[[BoardReturn alloc] init] autorelease];
[super viewDidLoad];
}
本文详细介绍了如何在iOS应用中设置文本输入控件的返回键为'DONE',并实现自定义的返回键处理逻辑。通过创建一个名为BoardReturn的NS对象,继承UITextFieldDelegate,实现了当文本字段获得焦点后按下返回键时的特定行为。在控制器中引入此类,确保文本字段在用户按下返回键后被取消编辑。
382

被折叠的 条评论
为什么被折叠?



