我有一个自定义的 UITableViewCell,里面有一个文本字段。我使用 IB 创建了它并有一个自定义类。
现在,我的问题是我想设置文本字段,以便在文本输入期间,如果用户在文本字段之外单击(没有按键盘上的返回/完成键),该字段将退出第一响应者。我明白,这样做我需要处理 Touch Up Inside 事件。但是,即使我已经完成了连接,我的 tableview 类也不会收到此事件。我假设它是因为它不是 UIcontrol 的子类,所以我不能让它成为它,因为它需要是 UITableViewCel。
那么解决办法是什么??我如何接收这些事件?
头文件:
#import <UIKit/UIKit.h>
@interface MMSingleTextFieldCell : UITableViewCell <UITextFieldDelegate>
// Properties
@property (weak, nonatomic) IBOutlet UITextField *singleTextField;
// Methods
- (IBAction)eventTouchUpOutside:(id)sender;
- (IBAction)eventTouchUpInside:(id)sender;
@end
类文件:
#import "MMSingleTextFieldCell.h"
@implementation MMSingleTextFieldCell
@synthesize singleTextField;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)eventTouchUpOutside:(id)sender {
[singleTextField resignFirstResponder];
}
- (IBAction)eventTouchUpInside:(id)sender {
[singleTextField resignFirstResponder];
}