次のようなカスタム クラスがあります。
@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);
}
回答ありがとうございます!