2011-04-11 7 views
0

나는 작업중인 탭 기반 응용 프로그램이 있습니다.UIScrollView에보기로드 및 내부 내용 가져 오기

필자는 DetailsView.x라는 뷰 컨트롤러를 가지고 있으며, DetailsView.xib라는 nib 파일이 있습니다. 여기에는 IBOutlet을 사용하여 DetailsView.m 뷰 컨트롤러에 연결된 UILabels가 두 개 있습니다. 탭 컨트롤러를 사용하여이 뷰 컨트롤러/뷰를로드하면 올바르게 작동하고 UILabels가 동적으로 채워집니다.

지금 내가 자세히 들어갈 수 있도록 대신있는 UIScrollView 안에이 전체보기를로드 할.

그래서 나는 DetailsHolder.xib라는 nib 파일로 DetailsHolder.m라는 또 다른 뷰 컨트롤러를 생성하고,이 할당 탭 표시 줄 컨트롤러.

첫 번째보기 (DetailsView)를 두 번째보기 (DetailsHolder)의 UIScrollView에로드하려면이 코드를 작성했습니다. 내가 DetailsHolder의 viewDidLoad에 방법에 쓴 :

DetailsView* detailsView = [[DetailsView alloc] initWithNibName:@"DetailsView" bundle: nil]; 
CGRect rect = detailsView.view.frame; 
CGSize size = rect.size; 
[scrollView addSubview: detailsView.view];  
scrollView.contentSize = CGSizeMake(320, size.height); 

이 올바르게있는 UIScrollView에 하위 뷰를로드하지만, 위해 DetailsView 내부의 라벨은 더 이상 아무것도 할 수 없습니다. DetailsView의 viewDidLoad 안에 NSLog를 넣을 때 아무 것도 기록하지 않습니다. 마치 nib ok를로드 한 것처럼 보이지만 더 이상 뷰 컨트롤러와 더 이상 연관되지 않습니다. 내가 여기서 무엇을 놓치고 있니? 나는 OBJ의 C/아이폰 OS에서 초보자의 비트를 해요 (하지만 다년간 액션 스크립트/자바 스크립트 지식이 사전에

감사합니다,

리치

편집 :. 요청에 따라 위해 DetailsView 내용 :

DetailsView.h :

#import <UIKit/UIKit.h> 
#import "AppModel.h" 

@interface DetailsView : UIViewController { 
    IBOutlet UITextView* textView; 
    IBOutlet UIImageView* imageView; 
} 

@end 

DetailsView.m

#import "DetailsView.h" 

@implementation DetailsView 

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

- (void)dealloc 
{ 
    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

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

- (void)viewWillAppear:(BOOL)animated 
{ 
    AppModel* model = [AppModel sharedInstance]; 

    [model loadData]; 

    int selectedLocation = [model getSelectedLocation]; 
    NSArray *locations = [model getLocations]; 
    NSArray *data = [locations objectAtIndex:selectedLocation]; 

    textView.text = [data objectAtIndex: 0]; 


    UIImage *theImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[data objectAtIndex: 4] ofType:@"jpg"]]; 

    imageView.image = theImage; 

} 

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

본질적으로 모든 작업은 모델에서 배열을 가져온 다음 이미지와 일부 텍스트를 내보기에 삽입하려고 시도하면서 singleton (내 모델)에서 selectedLocation (int)을 가져 오는 것입니다. 내 코코아 콩 파일에 UIImageView와 UITextView가 있습니다.이 두 개의 IBOutlets는 DetailsView.h에 선언되어 있습니다.

답변

0

이렇게보기 컨트롤러를 사용하면 많은 이벤트가보기 컨트롤러에서 발생하지 않습니다. viewWillAppear, viewWillDisappear 및 장치 회전 이벤트 내 생각 엔 그 중 일부 이벤트 메소드에서 초기화를 한 것 같습니다. DetailsView에 대한 코드를 게시하면 문제를 쉽게 찾을 수 있습니다.

+0

Tia에게 감사드립니다. 요청한대로 세부 정보보기 원본을 포함하도록 원래 게시물을 편집했습니다. – Rich

+0

이제'viewWillAppear' 메소드가 있는데, 실행되지 않을 것입니다. scrollview에 추가하기 전에 직접 호출하여 문제를 해결할 수 있습니다. – tia

관련 문제