Objective c UIActionSheet中的UITextField仅调用某些委托方法

Objective c UIActionSheet中的UITextField仅调用某些委托方法,objective-c,cocoa-touch,uitableview,uitextfield,uiactionsheet,Objective C,Cocoa Touch,Uitableview,Uitextfield,Uiactionsheet,下面的代码显示,当用户在表格视图单元格上做长按手势时,UIActionSheet启动,其中包含一个UITextField。点击UITextField时,键盘启动,textfield应开始编辑和textfield开始编辑被调用,但文本字段不接受按键点击 按回车键不会触发委托方法,但点击UIActionSheet按钮之一将触发textFieldShouldEndEditing,然后触发textfieldEndediting 我将文本字段设置为第一响应者,因此我不确定它为什么不接受键盘输入。有什么建议

下面的代码显示,当用户在表格视图单元格上做长按手势时,
UIActionSheet
启动,其中包含一个
UITextField
。点击
UITextField
时,键盘启动,
textfield应开始编辑
textfield开始编辑
被调用,但文本字段不接受按键点击

按回车键不会触发委托方法,但点击
UIActionSheet
按钮之一将触发
textFieldShouldEndEditing
,然后触发
textfieldEndediting

我将文本字段设置为第一响应者,因此我不确定它为什么不接受键盘输入。有什么建议吗

- (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;
}

UIExtFieldDelegate
UIActionSheetDelegate
是否在标题中


如果没有,则在将
textfield.delegate
设置为
self

时可能会出现问题。您的标题中是否有
UIExtFieldDelegate
UIActionSheetDelegate


如果没有,则在设置
文本字段时可能会出现问题。将
委派给
self
您的问题有点陈旧,但没有标记为已回答,因此如果对您或其他观众有帮助,我将发布我的解决方案。我一开始就遇到了与您相同的问题,最终的结果是UIActionSheet确实消耗了一些重要事件,这些事件对于让键盘正常工作是必要的。
不幸的是,我的链接发布代码只能以纵向方式运行,无论如何它都可以。

您的问题有点老,但没有标记为已回答,因此如果它对您或其他观众有帮助,我将发布我的解决方案。我一开始就遇到了与您相同的问题,最终的结果是UIActionSheet确实消耗了一些重要事件,这些事件对于让键盘正常工作是必要的。 不幸的是,我的链接张贴代码只能在纵向上工作,无论如何它都能做到