几天前我也遇到了同样的问题,我为这种情况编写了以下代码,首先我禁用了用户交互,dataTextfield
但我已经完成了触摸UITableCell
。我覆盖了简单UITouch
的事件方法而不是 textbegin 委托方法。请参阅我的以下代码。
在 tableviewController.h 文件中
#import <UIKit/UIKit.h>
#import "CustomTableCell.h"
@class CustomTableCell;
@interface PersonalInfoTableViewController : UITableViewController<CustomTableCellDelegate>{
@property(nonatomic, strong) UITextField *previousTextField;
@end
In tableviewController.m file
@implementation TableViewController
@synthesize previousTextField;
//When you create custom table cell set your CustomcellDelegate = self in tableView:cellForRowAtIndexPath method\
//also assign previousTextField to CustomTableCell textfield
-(void)tableViewTouch{
[previousTextField resignFirstResponder];
}
in CustomTableCell.h file
#import <UIKit/UIKit.h>
@protocol CustomTableCellDelegate
@optional
-(void)tableViewTouch;
@end
@interface CustomTableCell : UITableViewCell<UITextFieldDelegate>
@property(nonatomic, unsafe_unretained) id<CustomTableCellDelegate> delegate;
@property(nonatomic, weak) IBOutlet UITextFiled *theCellTextField;
@end
in CustomTableCell.m file
@synthesize theCellTextField, delegate;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
//Here my other method to show datepicker in popupViewController on tablecell.
[delegate tableViewTouch];
}
这是仅 ARC 的代码