UIView可以是UITextField委托

时间:2011-03-19 22:18:07

标签: uiview uitextfield xcode4 sigabrt uitextfielddelegate

当我尝试将UITextField的委托设置为我的UIView类时,我收到sigabrt错误。我使用过UITextFieldDelgate Protocal。这是我的代码

    nameField = [[UILabel alloc] initWithFrame:CGRectMake(130, 40, 200, 30)];
    [nameField setDelegate:self];
    nameField.placeholder = @"<Game Name>";
    nameField.textAlignment = UITextAlignmentCenter;
    [self addSubview:nameField];

1 个答案:

答案 0 :(得分:2)

您将在构造函数中使用UITextField,而不是UILabel。用以下内容替换您的第一个字符串:

nameField = [[UITextField alloc] initWithFrame:CGRectMake(130, 40, 200, 30)];