2017-08-11 40 views
-1

M使用目標c學習Container視圖。使用分段控制器使用兩個容器視圖

在此,嘗試使用分段控制器逐個顯示兩個容器。 兩個容器使用容器名稱是containerViewA,containerViewB。 我運行的應用程序,只有containerViewB加載。

代碼:

@interface ViewController() 
@property (weak, nonatomic) IBOutlet UIView *containerViewA; 
@property (weak, nonatomic) IBOutlet UIView *containerViewB; 
@end 

- (IBAction)ShowComponent:(UISegmentedControl *)sender { 
    if (sender.selectedSegmentIndex == 0) { 
     [UIView animateWithDuration:(0.5) animations:^{ 
      self.containerViewA.alpha = 1; 
      self.containerViewB.alpha = 0; 
     }]; 
    } else { 
     [UIView animateWithDuration:(0.5) animations:^{ 
      self.containerViewA.alpha = 0; 
      self.containerViewB.alpha = 1; 
     }]; 
    } 
} 

更新:

enter image description here

更新1:

故事板側板。

enter image description here

+0

是什麼問題? – Akhilrajtr

+0

第一個容器不顯示。@ Akhilrajtr –

+0

請嘗試在if之前打印sender.selectedSegmentIndex的值,並告訴它是什麼? – 3stud1ant3

回答

1

確保@property (weak, nonatomic) IBOutlet UIView *containerViewA;@property (weak, nonatomic) IBOutlet UIView *containerViewB;正確連接。

+1

請確保'@property(弱,非原子)IBOutlet UIView * containerViewA;'和'@property(weak,nonatomic)IBOutlet UIView * containerViewB;'連接在一起。所有其他似乎正確。 – Akhilrajtr

+0

表示你說兩個容器都是容器相互連接? –

+1

@GanganiRoshan No我認爲他的意思是說應該建立與故事板和這些網點中觀點的聯繫 – 3stud1ant3

相關問題