gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:05:09 25 4
gpt4 key购买 nike

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

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com