切换子视图控制器

- ( void ) configNvItem{
   
   
UISegmentedControl * segmentontrol = [[ UISegmentedControl alloc ] initWithItems : @[ @" 晒场 " , @" 活动 " ] ];
    segmentontrol.
tintColor = [ UIColor whiteColor ];
    segmentontrol.
frame = CGRectMake ( 0 , 0 , 200 , 34 );
   
NSDictionary *normalAttribute = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 19 ], NSFontAttributeName , [ UIColor redColor ], NSForegroundColorAttributeName , nil ];
   
NSDictionary *selectedAttribute = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 19 ], NSFontAttributeName , kThemeColor , NSForegroundColorAttributeName , nil ];
    [segmentontrol
setTitleTextAttributes :normalAttribute forState : UIControlStateNormal ];
    [segmentontrol
setTitleTextAttributes :selectedAttribute forState : UIControlStateSelected ];
    [segmentontrol
addTarget : self action : @selector (changeShowContent:) forControlEvents : UIControlEventValueChanged ];
    [segmentontrol
setSelectedSegmentIndex : 0 ];
    [
self showContentAtType : 0 ];
   
   
self . navigationItem . titleView = segmentontrol;
}

#pragma mark -User Interaction
- ( void ) changeShowContent:( UISegmentedControl *) segmentControl{
   
    [
self showContentAtType :segmentControl. selectedSegmentIndex ];
}

#pragma mark -Public Methods
/**
 * 
根据活动类型切换显示数据
 * 
@param type, 0: 晒场 1: 活动
 */

- (
void ) showContentAtType:( NSInteger ) type{
   
   
if (type == 0 ) {
       
        [
self . view addSubview : self . showViewController . view ];
        [
self . showViewController didMoveToParentViewController : self ];
       
        [
self . dynamicViewController willMoveToParentViewController : nil ];
        [
self . dynamicViewController . view removeFromSuperview ];
    }
else {
       
        [
self . view addSubview : self . dynamicViewController . view ];
        [
self . dynamicViewController didMoveToParentViewController : self ];
       
        [
self . showViewController willMoveToParentViewController : nil ];
        [
self . showViewController . view removeFromSuperview ];
    }
}

#pragma mark -Access
#pragma mark
延迟初始化
- ( MFFriendViewController *) showViewController{
   
   
if (! _showViewController ) {
       
       
_showViewController = [[ MFFriendViewController alloc ] init ];
        [
self addChildViewController : _showViewController ];
        
self . showViewController . view . frame = CGRectMake ( self . showViewController . view . frame . origin . x , self . view . frame . origin . y + 80 , self . view . frame . size . width , self . showViewController . view . frame . size . height - 100 );
    }
   
   
return _showViewController ;
}

- (
MFMineViewController *) dynamicViewController{
   
   
if (! _dynamicViewController ) {
       
       
_dynamicViewController = [[ MFMineViewController alloc ] init ];
        [
self addChildViewController : _dynamicViewController ];
       
self . dynamicViewController . view . frame = CGRectMake ( self . dynamicViewController . view . frame . origin . x , self . view . frame . origin . y + 80 , self . view . frame . size . width , self . dynamicViewController . view . frame . size . height - 100 );
       
    }
   
   
return _dynamicViewController ;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值