2014-02-25 4 views
0

내 앱의 간단한 가입 화면을 만들고 있습니다. 나는 Storyboards을 사용하지 않고 코드로 모든 것을하고있다. 그래서, 키보드를위한 공간을 허용하기 위해 내 화면의 동적 스크롤을 용이하게하기 위해 UITextFieldsUIScrollView 안에 삽입하는 표준 Apple 관행을 사용하고 있지만, 전혀 보이지 않습니다!UIViewController에 UIScrollView가 표시되지 않습니다.

코드 :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    [self registerForKeyboardNotifications]; 

    self.title = NSLocalizedString(@"Register", nil); 
    [self.navigationController setNavigationBarHidden:NO]; 

    // Because Rendering Bug in iOS 7 
    self.view.backgroundColor = [UIColor whiteColor]; 


    UIScrollView *scrollView = [[UIScrollView alloc] init]; 
    _scrollView.frame = self.view.frame; 
    _scrollView.scrollEnabled = YES; 
    _scrollView.showsVerticalScrollIndicator = YES; 
    _scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2); 
    [self.view addSubview:scrollView]; 

    // Personal Image View 
    UIButton *profileImageButton = [UIButton buttonWithType:UIButtonTypeSystem]; 
    profileImageButton.frame = CGRectMake(0, 0, 80, 80); 
    profileImageButton.center = CGPointMake(self.view.center.x, 80); 
    [profileImageButton setBackgroundImage:[UIImage imageNamed:@"DefaultAvatar"] forState:UIControlStateNormal]; 
    [profileImageButton addTarget:self action:@selector(uploadImage) forControlEvents:UIControlEventTouchUpInside]; 
    [_scrollView addSubview:profileImageButton]; 

    // Username Text Field 
    _usernameTextField = [[UITextField alloc] init]; 
    _usernameTextField.frame = CGRectMake(0, 0, self.view.frame.size.width, 64); 
    _usernameTextField.center = CGPointMake(self.view.center.x, 225); 
    _usernameTextField.placeholder = @"\tUsername"; 
    _usernameTextField.layer.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0].CGColor; 
    _usernameTextField.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:20.0]; 
    _usernameTextField.autocorrectionType = UITextAutocorrectionTypeNo; 
    [_scrollView addSubview:_usernameTextField]; 

    // Password Text Field 
    _passwordTextField = [[UITextField alloc] init]; 
    _passwordTextField.frame = CGRectMake(0, 0, self.view.frame.size.width, 64); 
    _passwordTextField.center = CGPointMake(self.view.center.x, 320); 
    _passwordTextField.placeholder = @"\tPassword"; 
    _passwordTextField.layer.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0].CGColor; 
    _passwordTextField.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:20.0]; 
    _passwordTextField.autocorrectionType = UITextAutocorrectionTypeNo; 
    [_scrollView addSubview:_passwordTextField]; 
} 

답변

2

UIScrollView *scrollView = [[UIScrollView alloc] init]; 
scrollView.frame = self.view.frame; 
scrollView.scrollEnabled = YES; 
scrollView.showsVerticalScrollIndicator = YES; 
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2); 
[self.view addSubview:scrollView]; 

을이 함께있는 ScrollView 선언을 교체 또는 당신이 "있는 ScrollView를"초기화 "_scrollView을 추가하기 때문에이

_scrollView = [[UIScrollView alloc] init]; 
_scrollView.frame = self.view.frame; 
_scrollView.scrollEnabled = YES; 
_scrollView.showsVerticalScrollIndicator = YES; 
_scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2); 
[self.view addSubview:scrollView]; 

처럼 이것은 "볼 수 있습니다. 그에 따라 scrollView에 모든 하위 뷰를 추가하십시오. 여기

1
UIScrollView *scrollView = [[UIScrollView alloc] init]; 
    _scrollView.frame = self.view.frame; 
    _scrollView.scrollEnabled = YES; 
    _scrollView.showsVerticalScrollIndicator = YES; 
    _scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2); 
    [self.view addSubview:scrollView]; //making mistake here 

, 당신이 만들고있는 실수는 ...

변화에이 라인 인스턴스 OBJ 동적 속성을 할당하고 하위 뷰 같은 지역 OBJ를 추가 [self.view의 addSubview를 :있는 ScrollView] to [self.view addSubview : _scrollView];

그리고 init _scrollview도 할당해야합니다.

관련 문제