2013-02-27 53 views
0

我有一個窗體視圖,其中包含一些UITextFields。我想在滾動視圖中添加窗體的視圖。在視圖中添加scrollView iphone

以下是我如何設計的形式和它的文本框:我在「textFieldDidBeginEditing補充說:」這

- (UIView *)Form 
{ 
    if (!_Form) { 

     CGRect frame = CGRectMake(0.0, Height, Width, 310.0); 
     UIView *container = [[UIView alloc] initWithFrame:frame]; 

     CGFloat y = 15.0; 
     frame = CGRectMake(15.0, y, width, height); 
     UITextField *field = [[UITextField alloc] initWithFrame:frame]; 
     [ 
     field.placeholder = @"text"; 


     CGFloat spacing = 8.0; 
     y = frame.origin.y + height + spacing; 
     frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text6"; 


     frame.size.height = 200.0; 

     y = frame.origin.y + height + space; 
     frame = CGRectMake(15.0, y, width - 2*15.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text1*"; 



     y = frame.origin.y + height + 16.0; 
     CGFloat w = (kDeviceWidth - 2 * 15.0)/2; 
     frame = CGRectMake(15.0, y, w - 2.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text3*"; 


     frame = CGRectMake(15.0 + w + 2.0, y, w - 2.0, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text4*"; 


     y = frame.origin.y + height + spacevalue; 
     frame = CGRectMake(15.0, y, w, height); 
     field = [[UITextField alloc] initWithFrame:frame]; 

     field.placeholder = @"text5"; 



     y = frame.origin.y + height + 20.0; 
     frame = CGRectMake((frame.size.width - 192.0)/2, y, 192.0, 34.0); 



     y = frame.origin.y + height + 8.0; 
     frame = CGRectMake((frame.size.width - 192.0)/2, y, 192.0, 34.0); 
    } 
    return _Form; 
} 

:(signView是具有形式的觀點,在它的視圖)

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.signView.frame.size.width, self.signView.frame.size.height)]; 
     scroll.pagingEnabled = YES; 
     [scroll addSubview:self.Form]; 

     scroll.contentSize = CGSizeMake(self.signView.frame.size.width*self.Form.frame.size.width, self.Form.frame.size.height); 

但是當我點擊一個textfiled所有窗體視圖的textfields消失後,我可以將scrollview嵌入到視圖中嗎?

感謝

回答

0

你正在做return _Form;

什麼是_Form

據我所知,你必須返回container。 所以使它

return container;

並且正在UITextField但你在哪裏添加爲子視圖您的視圖,你只是創建它。

+0

我創建在窗體的視圖文本框是你的容器「 - (UIView的*)表」 – 2013-02-27 17:40:51

+0

你正在做的回報_form ;那麼這是什麼_Form – Rajneesh071 2013-02-28 07:58:27

+0

_form是一個註冊表單視圖 – 2013-02-28 20:06:39

0

是的,但你必須把你的UITextField在容器中加入子視圖

if (!_form) { 
     //YOUR STUFF then -> add container subview your view 
     [container addSubview:yourTEXTField] 
     return container; 
    } 
    else { 
     return _form; 
    } 
+0

你能幫我添加一個滾動條到我已經實現的視圖嗎? – 2013-02-27 18:38:42