1

아래 코드는 사용자가 테이블 뷰 셀에서 길게 누르는 제스처를 수행하면 UIActionSheetUITextField으로 시작된다는 것을 보여줍니다. UITextField을 탭하면 키보드가 시작되고 textFieldShouldBeginEditingtextFieldDidBeginEditing이 호출되지만 텍스트 필드는 키 탭을 허용하지 않습니다.UITextField의 UIActionSheet에서 일부 대리자 메서드 만 호출

반환 키를 누르면 대리자 메서드가 트리거되지 않지만 UIActionSheet 단추 중 하나를 누르면 textFieldShouldEndEditing이 표시되고 textFieldDidEndEditing이 트리거됩니다.

textField가 첫 번째 응답자가되도록 설정 했으므로 키보드 입력을받지 않는 이유가 확실하지 않습니다. 어떤 제안?

- (void)longPress:(UILongPressGestureRecognizer *)gesture 
{ 
    // only when gesture was recognized, not when ended 
    if (gesture.state == UIGestureRecognizerStateBegan) 
    { 
     // get affected cell 
     SinTableViewCell *cell = (SinTableViewCell *)[gesture view]; 

     // get indexPath of cell 
     NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; 

     // do something with this action 
     NSLog(@"Long-pressed cell at row %d", indexPath); 
     AppDelegate_Shared *appDelegate = (AppDelegate_Shared*)[UIApplication sharedApplication].delegate; 

     //setup UITextField for the UIActionSheet 
     UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 170, 320, 200)]; 
     textField.borderStyle  = UITextBorderStyleBezel; 
     textField.backgroundColor = UIColorFromRGB(0XFFFFFF); 
     textField.text   = @""; 
     textField.delegate  = self; 

     [textField setKeyboardType:UIKeyboardTypeAlphabet]; 
     [textField setKeyboardAppearance:UIKeyboardAppearanceAlert]; 

     //setup UIActionSheet 
     UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Add Notes" 
                  delegate:self 
                cancelButtonTitle:@"Cancel" 
               destructiveButtonTitle:nil 
                otherButtonTitles: @"Save", nil]; 

     [asheet showFromTabBar:appDelegate.tabBarController.tabBar]; 
     [asheet setFrame:CGRectMake(0, 100, 320,380)]; 
     [asheet insertSubview:textField atIndex:0]; 
     //[textField becomeFirstResponder]; 
     //memory management 
     [textField release]; 
     [asheet release]; 
    } 
} 

#pragma mark - 
#pragma mark UIActionSheetDelegate 
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex { 

} 
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { 

} 

#pragma mark - 
#pragma mark UITextFieldDelegate 
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    NSLog(@"textFieldShouldBeginEditing"); 
    return YES; 
}  
- (void)textFieldDidBeginEditing:(UITextField *)textField { 
    NSLog(@"textFieldDidBeginEditing"); 
    [textField becomeFirstResponder]; 
} 
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField { 
    NSLog(@"textFieldShouldEndEditing"); 
    return YES; 
} 

//should save the notes value here, I think 
- (void)textFieldDidEndEditing:(UITextField *)textField { 
    NSLog(@"textFieldDidEndEditing"); 
    [textField resignFirstResponder]; 
} 

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ 
    return YES; 
} 

- (BOOL)textFieldShouldClear:(UITextField *)textField { 
    NSLog(@"textFieldShouldClearEditing"); 
    return YES; 
} 
- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    NSLog(@"in textFieldShouldReturn"); 
    return YES; 
} 

답변

0

헤더에 UITextFieldDelegateUIActionSheetDelegate이 있습니까? textfield.delegate

1

self에 질문을 설정하는 동안

그렇지 않으면, 문제가있을 수 것은 조금 오래된하지만 대답으로 표시되지 않습니다, 그래서 당신이나 다른 뷰어에 도움이 경우 내 솔루션 from my own SO question을 게시 할 수 있습니다. UIActionSheet가 실제로 키보드를 올바로 작동시키는 데 필요한 몇 가지 중요한 이벤트를 실제로 먹는다는 사실에서 끝났습니다. 내 연결된 게시 된 코드는 불행히도 세로 방향으로 만 작동합니다. 어쨌든 않습니다.