UITextField - 无法输入文本。键盘没有响应

时间:2012-01-26 16:19:18

标签: iphone uitextfield objective-c-2.0 uitextfielddelegate

我有UIVextField和UITextField。

#import <UIKit/UIKit.h>

@interface TextMemoViewController : UIViewController<UITextFieldDelegate> 

@property (unsafe_unretained, nonatomic) IBOutlet UITextField *textMemo;

@end

在实施代码中是下一个:

#import "TextMemoViewController.h"

@implementation TextMemoViewController
@synthesize textMemo;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.textMemo.delegate = self;


}
//.....
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return  YES;
}

问题是,当我点击textField - 键盘出现时,但没有任何东西可以按下它。所有模拟器都挂断了。此行为无法输入文本。

我有几个带有textFields的UIViewControllers,一切都还可以。但在这里,我找不到它发生的原因。 我已经在Xcode中清理了DerivedData,重新启动了所有模拟器并重置了它们的设置。在iPhone上的情况相同。 有没有人有想法?

4 个答案:

答案 0 :(得分:1)

请检查您的UIAlertView代表。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  // DO NOT Create Other UIAlertView.
}

我认为这是iOS 5.1上的错误。

答案 1 :(得分:0)

我认为你需要改变:

@property (unsafe_unretained, nonatomic) IBOutlet UITextField *textMemo;

为:

@property (strong, nonatomic) IBOutlet UITextField *textMemo;

差异为strong而非unsafe_unretained。我相信你的观点没有得到解决,这就是你无法与之互动的原因。

答案 2 :(得分:0)

//make sure you use this delegate and add all your textfields..
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch* touch = [[event allTouches] anyObject];
//  NSLog(@"Touches began called.");

//fill these in with all your textfields..
if([UserFirstName isFirstResponder] && [touch view] != UserFirstName){
    [UserFirstName resignFirstResponder];
}

}

答案 3 :(得分:-1)

迟到的好,比从来没有好过。)

谢谢大家,但正如我很久以前发现的那样,问题出现在以前的一些观点中没有辞职的响应者。 在这种情况下,视图被其他视图覆盖,但响应者没有被更改。

也许有人会觉得这很有用。