UISegmentedControl uiNavigationController

时间:2013-01-30 10:15:14

标签: ios uiviewcontroller uinavigationcontroller uisegmentedcontrol

我正在尝试制作一些自定义视图,我想知道如何实现这样的东西,你有一个UISegmentControl(或类似的东西),你在不同的视图控制器之间切换,但段控制仍然在相同的地方(不要介意图片的大小不同)。像导航控制器,但有一个段而不是它。任何想法将不胜感激。感谢

enter image description here enter image description here

3 个答案:

答案 0 :(得分:2)

这可以很容易地完成。您只需使用导航控制器,但隐藏所有视图的导航栏。然后你可以使用

[self.navigationController pushViewController:@"Your viewController to which you want to navigate" animated:YES];

选择段索引。并且从任何一个视图控制器返回,你只需要实现这个

[self.navigationController popViewControllerAnimated:YES];选择的段索引的按钮操作。我希望这会对你有所帮助。快乐的编码.. !!!

答案 1 :(得分:0)

您可以创建带有段控件和数组的ViewController,它将包含其他控制器。 在段更改时,您应该从数组中的一个控制器获取视图,并将其像子视图一样添加到父ViewControllerView。 这看起来像这样

//in ViewControllerView.m
-(void)touchUpInsideSegmentIndex:(NSUInteger)segmentIndex {
   //delegate is your ViewController
    UIView * newToolView = [delegate viewAtIndex:segmentIndex];
    //contentView declared in ViewControllerView.h
    if (newToolView != contentView && newToolView) {
        [contentView removeFromSuperview];
        [contentView release];
        contentView = [newToolView retain];
        [self addSubview:contentView];
        [self setNeedsLayout];
    }
}

//in ViewController.m
- (UIView*)viewAtIndex:(NSInteger)index {
    //yourControllersArray is an array of your controllers
    if (index < 0 || index >= [yourControllersArray count]) {       
        NSLog(@"View At Wrong Index %d (max=%d)", index, [yourControllersArray count]);
        return nil;
    }
    return [[yourControllersArray objectAtIndex: index] view];
}

答案 2 :(得分:0)

  1. 将UISegmentedControl放在导航栏中。
  2. 将导航栏设置为透明。
  3. 在UISegmentedControl方法中,从UINavigationController堆栈推送和弹出视图控制器,或显示和解除模态
相关问题