2012-04-28 210 views
0

使用xcode 4.3.2不能滾動ScrollView

我是新來的,所以請保留任何答案。我試圖遵循例子,但沒有任何工作。我有一個包含文本框的頁面。底部的那些被鍵盤隱藏起來。我想要的只是能夠向上滾動,以便填寫那些隱藏的字段。我附加了我的.m文件。

#import "Engine Editor.h" 

@interface Engine_Editor 

@end 

@implementation Engine_Editor 
@synthesize Enginescroll; 
@synthesize MainEngineField; 
@synthesize MainSerialField; 
@synthesize MainServiceField; 
@synthesize AuxEngineField; 
@synthesize AuxSerialField; 
@synthesize AuxServiceField; 
@synthesize BLANK; 
@synthesize ReturnEngine; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
    { 
self.MainEngineField.text=((ViewController *)self.presentingViewController).MainEngineLabel.text; 
self.MainSerialField.text=((ViewController *)self.presentingViewController).MainSerialLabel.text; 
self.MainServiceField.text=((ViewController *)self.presentingViewController).MainServiceLabel.text; 
self.AuxEngineField.text=((ViewController *)self.presentingViewController).AuxEngineLabel.text; 
self.AuxSerialField.text=((ViewController *)self.presentingViewController).AuxSerialLabel.text; 
self.AuxServiceField.text=((ViewController *)self.presentingViewController).AuxServiceLabel.text; 



[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
[self setEnginescroll:nil]; 
[self setMainEngineField:nil]; 
[self setMainSerialField:nil]; 
[self setMainServiceField:nil]; 
[self setAuxEngineField:nil]; 
[self setAuxSerialField:nil]; 
[self setAuxServiceField:nil]; 
[self setReturnEngine:nil]; 
[self setBLANK:nil]; 

[Enginescroll setScrollEnabled:YES]; 
[Enginescroll setShowsVerticalScrollIndicator:YES]; 
[Enginescroll setFrame:CGRectMake(0, 55, 320, 320)]; 
[Enginescroll setContentSize:CGSizeMake(320, 600)]; 



[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (IBAction)DismissEditor:(id)sender { 

((ViewController *)self.presentingViewController).MainEngineLabel.text=self.MainEngineField.text; 
[self dismissViewControllerAnimated:YES completion:Nil]; 
((ViewController *)self.presentingViewController).MainSerialLabel.text=self.MainSerialField.text; 
[self dismissViewControllerAnimated:YES completion:Nil]; 
((ViewController *)self.presentingViewController).MainServiceLabel.text=self.MainServiceField.text; 
[self dismissViewControllerAnimated:YES completion:Nil]; 
((ViewController *)self.presentingViewController).AuxEngineLabel.text=self.AuxEngineField.text; 
[self dismissViewControllerAnimated:YES completion:Nil]; 
((ViewController *)self.presentingViewController).AuxSerialLabel.text=self.AuxSerialField.text; 
[self dismissViewControllerAnimated:YES completion:Nil]; 
((ViewController *)self.presentingViewController).AuxServiceLabel.text=self.AuxServiceField.text; 
[self dismissViewControllerAnimated:YES completion:Nil]; 

} 

- (IBAction)HideKeyBoard:(id)sender { 
} 
@end 

回答

1

您可以UIKeyboardDidShowNotification註冊並設置滾動視圖的contentInset使得底部插圖等於鍵盤框架的高度(通知的userInfo的看到UIKeyboardFrameEndUserInfoKey鍵)。同樣,當您收到UIKeyboardWillHideNotification時,只需將contentInset重置爲UIEdgeInsetsZero即可。