分段控制UIpopover

时间:2012-01-31 08:25:06

标签: objective-c scrollview uipopover

任何人都知道如何在UIpopover中放置分段控件的链接/教程?其中一个视图具有滚动视图,当选择了段索引时,滚动视图显示在弹出窗口的其余部分顶部,并且无法选择该段

- (IBAction) segmentAction:(id)sender 
{
    UISegmentedControl* control = sender ;

    if( [control selectedSegmentIndex] == 0 )
    {

        [ self.view addSubview:Firstview1] ;
    }
    if( [control selectedSegmentIndex] == 1 ) 
    {  

        [scrollview1 setScrollEnabled:YES];
        [scrollview1 setContentSize:CGSizeMake(320, 480)];
        self->Secondview2=scrollview1;
        [scrollview1 release];

        [ self.view addSubview:Secondview2] ;
    }
    if( [control selectedSegmentIndex] == 2 ) 
    {
        [ self.view addSubview:Thirdview3] ;
    }


}

建议将不胜感激

1 个答案:

答案 0 :(得分:1)

首先,当您使用分段控件时,不要只在每个分段中添加子视图,因为当您切换分段时,子视图不会被删除。对于滚动视图,只需更改内容大小。所以最好的方法是: -

viewDidLoad()
{
[ self.view addSubview:Firstview1] ;
Firstview1.hidden = yes;
[ self.view addSubview:Secondview2] ;
Secondview2.hidden = yes;
[ self.view addSubview:Thirdview3] ;
Thirdview3.hidden = yes;

}

(IBAction) segmentAction:(id)sender 
{
    UISegmentedControl* control = sender ;

    if( [control selectedSegmentIndex] == 0 )
    {
Firstview1.hidden = no;
       Secondview2.hidden = yes;
Thirdview3.hidden = yes;
    }
    if( [control selectedSegmentIndex] == 1 ) 
    {  

        [scrollview1 setScrollEnabled:YES];
        [scrollview1 setContentSize:CGSizeMake(320, 480)];
        self->Secondview2=scrollview1;
        [scrollview1 release];

       Firstview1.hidden = yes;
       Secondview2.hidden = no;
Thirdview3.hidden = yes;
    }
    if( [control selectedSegmentIndex] == 2 ) 
    {
        Firstview1.hidden = yes;
       Secondview2.hidden = yes;
Thirdview3.hidden = no;
    }

}