【问题标题】:Having problem with pushViewController!! HelppushViewController 有问题!!帮助
【发布时间】:2011-01-17 22:33:07
【问题描述】:
tabBarController = [[UITabBarController alloc] init];   //Create a tab bar  
view1 = [[View1 alloc] init];   //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];
view2 = [[View2 alloc] init];   //create the second view
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:view2];
navigationController2.navigationBar.tintColor =[UIColor blackColor];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController1, navigationController2,nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

上面的代码来自我的 appDelegate 类 (applicationDidFinishLaunching)。 View1 和 View2 是 UIViewController。这就是我最初设计我的应用程序的方式,这些应用程序有两个选项卡(view1 和 view2)。下面的代码实现了当用户向左或向右滑动时 View1 中发生的情况。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"I am in touches began  methods");

UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.view];

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];

CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);

if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
    //Set Animation Properties
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration: 1];

    if(gestureStartPoint.x > currentPosition.x){    //I am trying to move right

        ViewControllerTemplate *newView = [[ViewControllerTemplate alloc] initWithNibName:@"ViewControllerTemplate" bundle:nil];
        //Transition spin right
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
        //Push OnTo NavigationController
        [self.navigationController pushViewController:newView animated:YES];        
    }
    else {  //I am trying to move left
        if([viewDelegate getCurrentViewID] > 0){    //At view 0, should not pop anymore view
            //Transition Spin left
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    [UIView commitAnimations];
}
}

差不多吧,它只是说当用户向右滑动时,它会创建一个新视图(ViewControllerTemplate)和pushViewController,当用户向左滑动时,它会弹出ViewController。但是,由于我改变主意并且不想实现标签栏。因此,我将 appDelegate 中的 applicationDidFinishLaunching 中的代码更改为下面的代码,并且 View1.m 中 touchesMoved 中的 pushViewController 停止工作。我确信它会到达那里,但是当它 pushViewController 的 newView 时,什么也没有发生。我觉得当我拿出 UINavigationController 时,我的视图不再正确地推送到堆栈上。知道为什么,以及如何解决它

view1 = [[View1 alloc] init];
[window addSubview:View1.view];

【问题讨论】:

    标签: iphone uiviewcontroller uinavigationcontroller pushviewcontroller


    【解决方案1】:

    如果有人遇到同样的问题,这里是解决方案 将我所拥有的 applicationDidFinishLaunching() 替换为此

    view1 = [[View1 alloc] initWithNibName:@"View1" bundle:nil];    //Create the first view
    UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
    navigationController1.navigationBar.tintColor =[UIColor blackColor];
    view1 = navigationController1;  
    [window addSubview:view1.view];
    [window makeKeyAndVisible];
    

    【讨论】:

    • 您知道如何像以前一样将数据推送到 UITouch 上的另一个视图。就像我们在 didselectforrowatindexpath 上做的那样。
    猜你喜欢
    • 2011-10-19
    • 2011-05-28
    • 2011-02-11
    • 1970-01-01
    • 2011-02-02
    • 2012-01-12
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多