1
我使用自定義UITableViewCell製作UITableView。 我把一個UITextField放在我的UITableViewCell中,當我添加UITapGestureRecognizer到我的UITableView時,點擊一個任意單元格就可以獲得CGPoint.y。UITapGestureRecognizer選擇器不工作
!!!我的問題在這裏!!! 當我專注於任何單元格中的UITextField時,我的UITapGestureRecognizer選擇器不工作 !!!但是當我點擊除了UITextField UITapGestureRecognizer選擇器工作的單元格的任何地方!
我想在UITextField UITapGestureRecognizer選擇器工作時獲得焦點並獲得屏幕的point.y!
這是我的代碼:除非你已經設置的屬性
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.prsnTable];
UITapGestureRecognizer *tpgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapPress:)];
[self.prsnTable addGestureRecognizer:tpgr];
}
- (void)handleTapPress:(UITapGestureRecognizer*)gestureRecognizer{
CGPoint p = [gestureRecognizer locationInView:self.prsnTable];
NSLog(@"%f",p.y);
}
- (UITableView*)prsnTable {
if (!_prsnTable) {
CGRect tableFrame = CGRectMake(0,0,CGRectGetWidth(self.view.frame),CGRectGetHeight(self.view.frame)-70);
_prsnTable =[[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
_prsnTable.scrollEnabled = YES;
_prsnTable.delegate = self;
_prsnTable.dataSource = self;
_prsnTable.showsVerticalScrollIndicator = YES;
[_prsnTable setBackgroundColor:[UIColor clearColor]];
_prsnTable.separatorStyle = UITableViewCellSeparatorStyleNone;
_prsnTable.contentInset = UIEdgeInsetsMake(0,0,0,0);
}
return _prsnTable;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SourCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SourCell"];
if (!cell) {
cell = [[SourCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SourCell"];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setBackgroundColor:[UIColor clearColor]];
MFTextField *tfName = (MFTextField*)[cell viewWithTag:11];
tfName.delegate = self;
return cell;
}
#pragma mark - TextField Delegate
- (void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"focus");
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(@"aaaaaa");
return YES;
}