textFieldShouldBeginEditing未在自定义类(委托集)中调用

时间:2012-12-23 14:14:43

标签: 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);

}

感谢您的回答!

1 个答案:

答案 0 :(得分:2)

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

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

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

相关问题