我有一個自定義類這樣的:textFieldShouldBeginEditing不會被調用的自定義類(代表集)
@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);
}
謝謝回答!
當你調用'有用的鏈接[查看addSubview:界面];',什麼是'view' ......,什麼方法是裏面? (另外,不帶'init'調用'alloc'通常是個好主意。) –
「view」是在我自己的「viewofPlist」例程formparser.m中創建的一個uiview。它返回在上面的例程中的視圖... 我已經改變了我的分配例程:formParser * fParse = [[FormParser alloc] init]但無濟於事......但是,謝謝你的提示;) –
編輯我的問題給你在formparser.m例程 –