ios - 自定义类(委托(delegate)集)中未调用 textFieldShouldBeginEditing

标签 ios xcode delegates uitextfield uitextfielddelegate

我有一个这样的自定义类:

@interface formParser : NSObject <UITextFieldDelegate> {
....

在 .m 中,我创建了一个 UITextField 元素,如下所示:

UITextField *ui = [[UITextField alloc] initWithFrame:CGRectMake(left, top, width, height)];
[ui setDelegate:self];
[ui setPlaceholder:[dict_elementInfo objectForKey:@"placeholder"]];
[ui setBorderStyle:UITextBorderStyleLine];
[view addSubview:ui];

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
NSLog(@"should begin");
return NO;
}

我的问题是 shouldbegin 从未被调用过。当我在“普通”UIViewController 类上尝试这种技术时,它工作得很好,但是在我的自定义对象中这样做它从未调用过。任何人都可以找出原因吗?

我的自定义类调用如下:

formParser *fParse = [[formParser alloc] init];
UIView *view_formBackground = [fParse viewOfPlist:@"form" initSize:CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)];
view_formBackground.backgroundColor = [UIColor whiteColor];


//add views to main view
[scrollView addSubview:view_formBackground];
[self.view addSubview:scrollView];

另外,formparser.m中的viewofplist如下:

-(UIView *)viewOfPlist:(NSString *)filename initSize:(CGRect)size
{
ypos_element_left = 40; ypos_element_right = 40;

view = [[UIView alloc] initWithFrame:size];

//load plist
NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
rootArray = [dict objectForKey:@"form"];

//loop door alle UI entries in de dict.
for (NSDictionary *dict_UIElement in rootArray)
{
    NSString *UIType = [dict_UIElement objectForKey:@"type"];
    if ([UIType isEqualToString:@"ui_empty"])       [self handle_uiempty:dict_UIElement];
    if ([UIType isEqualToString:@"ui_multiselect"]) [self handle_uimultiselect:dict_UIElement];
    if ([UIType isEqualToString:@"ui_label"])       [self handle_uilabel:dict_UIElement];
    if ([UIType isEqualToString:@"ui_textfield"])   [self handle_uitextfield:dict_UIElement];
    if ([UIType isEqualToString:@"ui_choicefield"]) [self handle_uichoicefield:dict_UIElement];
    if ([UIType isEqualToString:@"ui_calendar"])    [self handle_uicalendar:dict_UIElement];

}


return (view);

感谢您的回答!

最佳答案

您的分配是否超出范围并被 ARC 清理?

有关响应链如何工作的有用链接..

http://developer.apple.com/library/ios/#documentation/general/conceptual/Devpedia-CocoaApp/Responder.html

关于ios - 自定义类(委托(delegate)集)中未调用 textFieldShouldBeginEditing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14011657/

相关文章:

c# - 委托(delegate)大会的主要流程是什么?

enums - Kotlin ENUM 类具有由委托(delegate)实现的通用接口(interface)

ios 我可以更改默认密码屏幕行为或创建始终监听的按钮组合吗

iphone - iOS5.0.1上的内存泄漏drawInRect

ios - 无法将数据插入到iOS中的sqlite3中

xcode - 将应用程序添加到App Store

ios - 类方法单例对象可以响应委托(delegate)调用吗?

ipad - UITableview 在 UIPopover 中无法正确旋转

xcode - 如何将 OpenSSL 添加到 Xcode 项目

ios - 在 Xcode 数据模型编辑器中的配置之间移动实体