我想用兩個UIViews
segmentControl
。現在這兩個UIViews
都嵌入了own.These UIViews
應該的scrollView
顯示爲一臺之間切換,所以我把它們放在對方(在XIB)的頂部。而當點擊segmentControl
時,我試圖相應地隱藏/顯示它們。但到目前爲止,我無法在兩者之間切換。下面還嘗試瞭解決方案。但它只適用於隨機單元,並且無法在所有單元中切換。缺少什麼?如何通過使用段控制ios在兩個UIViews之間正確切換?
這就是我如何設置隱藏在didSelectRow
中的上部視圖,其中我擴大了tableViewCell
。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if ([self.expandedCells containsObject:indexPath]) {
expCell.upperContainer.hidden = NO;
expCell.upperScroll.hidden = NO;
[self.expandedCells removeObject:indexPath];
}else{
isExpanded=YES;
[self.expandedCells addObject:indexPath];
//hide upper container
if (!expCell.upperContainer.hidden) {
expCell.upperContainer.hidden = YES;
}
if (!expCell.upperScroll.hidden) {
expCell.upperScroll.hidden =YES;
}
}
[self.bTableView beginUpdates];
[self.bTableView reloadData];
[self.bTableView endUpdates];
}
然後在segmentControl的expandedCell上單擊我正在執行以下操作。
-(void)selectDeckView:(UISegmentedControl*)sender{
if (sender.selectedSegmentIndex==0) {
NSLog(@"segment 0"); //executes
expCell.lowerDeckView.hidden=NO;
expCell.lowerScrollView.hidden=NO;
expCell.upperScroll.hidden=YES;
expCell.upperContainer.hidden=YES;
}else if (sender.selectedSegmentIndex==1){
NSLog(@"segment 1"); //executes
expCell.lowerDeckView.hidden=YES;
expCell.lowerScrollView.hidden=YES;
expCell.upperContainer.hidden=NO;
expCell.upperScroll.hidden=NO;
}
}
是的,我也想過這件事。不幸的是,我的視圖和我的擴展表單元格一樣,現在放在XIB中。如果這種情況甚至可能,我如何添加子視圖。 – iSD 2014-09-04 13:15:07
你可以將它們拆分成單獨的nib,然後通過這樣做來爲每個nib創建一個子視圖控制器:UIViewController * viewController = [[UIViewController alloc] initWithNibName:@「myNib」bundle:nil]; – pmacro 2014-09-04 13:28:00
嘗試解決您的問題。我有一個問題,因爲我正在使用當前實現填充當前視圖控制器中的視圖。我可以從我的父視圖控制器填充childViewControllers視圖,然後加載它們?還是要做其他事情? – iSD 2014-09-05 11:47:56