1

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

@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);

}

谢谢回答!

4

1 回答 1

2

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

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

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

于 2012-12-23T14:30:34.407 回答