2012-02-13 2 views
1

모두.뷰가 전환되면 tabBar가 사라집니다. 왜?

두 개의보기 (ScrollView 및 TableView)로 앱 TabBar를 만들고 있습니다.

응용 프로그램이 시작되면 TabBar 단추가 나타나고 두 개의보기를 변경할 수 있습니다.

TableView에서 누름 단추를 프로그래밍하여 ScrollView를 변경하면보기가 변경됩니다. 하지만 TabBar가 사라집니다.

누군가 도와주세요! 조언 해줘.

응용 프로그램 이미지 : http://www.0502.me/help/xcode_why.png

항목보기 컨트롤러 (있는 TableView)

#import "FirstViewController.h" 
#import "SecondViewController.h" 

@implementation FirstViewController 

- (void)didReceiveMemoryWarning 
{ 
    [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, typically from a nib. 
} 

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

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
    } else { 
     return YES; 
    } 
} 

- (IBAction)pageOne:(id)sender { 
//Below code is switch View 
    SecondViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondView"]; 
    [self presentModalViewController:secondView animated:YES]; 
} 

- (IBAction)pageTwo:(id)sender { 
} 

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

두 번째보기 컨트롤러 (있는 ScrollView)

#import "SecondViewController.h" 

@implementation SecondViewController 

- (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)pageLoad:(UIScrollView *)scrollView { 
    currentPage = scrollView.contentOffset.x/scrollView.bounds.size.width; 
    int pageWidth = self.view.frame.size.width; 
    int pageHeight = self.view.frame.size.height; 

    prevPage.frame = CGRectMake(
           pageWidth * (currentPage - 1), 
           0, 
           pageWidth, 
           pageHeight 
           ); 
    if (currentPage > 0) { 
     [prevPage setImage:[NSString stringWithFormat:@"%d", (currentPage - 1) % kPageNum]]; 
     prevPage.hidden = NO; 
    } else { 
     prevPage.hidden = YES; 
    } 

    currPage.frame = CGRectMake(
           pageWidth * currentPage, 
           0, 
           pageWidth, 
           pageHeight 
           ); 

    [currPage setImage:[NSString stringWithFormat:@"%d", currentPage % kPageNum]]; 
    currPage.hidden = NO; 

    nextPage.frame = CGRectMake(
           pageWidth * (currentPage + 1), 
           0, 
           pageWidth, 
           pageHeight 
           ); 


    if (currentPage < (kPageNum - 1)) { 
     [nextPage setImage:[NSString stringWithFormat:@"%d", (currentPage + 1) % kPageNum]]; 
     nextPage.hidden = NO; 
    } else { 
     nextPage.hidden = YES; 
    } 

} 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIScrollView *scrollView = [[UIScrollView alloc] init]; 

    scrollView.frame = self.view.bounds; 
    scrollView.contentSize = CGSizeMake(self.view.frame.size.width * kPageNum, self.view.frame.size.height); 
    scrollView.pagingEnabled = YES; 
    [self.view addSubview:scrollView]; 

    scrollView.delegate = self; 

    prevPage = [[PageView alloc] initWithFrame:self.view.bounds]; 
    [scrollView addSubview:prevPage]; 

    currPage = [[PageView alloc] initWithFrame:self.view.bounds]; 
    [scrollView addSubview:currPage]; 

    nextPage = [[PageView alloc] initWithFrame:self.view.bounds]; 
    [scrollView addSubview:nextPage]; 

    [self pageLoad:scrollView]; 
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    CGFloat position = scrollView.contentOffset.x/scrollView.bounds.size.width; 
    CGFloat delta = position - (CGFloat)currentPage; 

    if (fabs(delta) >= 1.0f) { 
     [self pageLoad:scrollView]; 
    } 
} 

- (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 

답변

2

당신은 모달보기로 제시하고 있습니다. 귀하의 질문을 이해하면 UITabBar에서 선택한 항목을 전환하기 만하면됩니다. 당신이 좋아하는 작업을 수행 할 수 있습니다

인덱스 전환하려는 UIViewController의 인덱스를 나타내는 정수입니다
self.tabBarController.selectedIndex = index; 

. 귀하의 경우 인덱스는 0이어야합니다.

+0

감사합니다. edc1591, 코드를 다시 작성한 다음 수집을 전환하십시오! –

관련 문제