2013-08-21 151 views
0

sample image如何將子視圖添加到子視圖的滾動視圖

如何創建此視圖。用於添加滾動視圖

yPos=0; 
for (int i=0; i<24; i++) { 

    UIView *timeView=[[UIView alloc]initWithFrame:CGRectMake(71, yPos, 909, 60)]; 
    timeView.userInteractionEnabled=TRUE; 
    timeView.exclusiveTouch=YES; 
    if (i==4) { 
     UIView *ssview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 80)]; 
     ssview.tag=1; 
     ssview.userInteractionEnabled=TRUE; 
     UILabel *recurenceId=[[UILabel alloc]init]; 
     [email protected]"A12334"; 

     [ssview addSubview:recurenceId]; 
     ssview.backgroundColor=[UIColor orangeColor]; 


     [timeView addSubview:ssview]; 
     [ssview addGestureRecognizer:tap]; 



    } 

這裏ssview高度 代碼比timeview.so它被加入到下一個子視圖也

這裏的每行是滾動視圖的子視圖更多。 現在我不得不添加另一個綠色的視圖。

+0

您的問題是什麼? – Kepler

+0

如果在第12行添加了greenView,它必須根據其高度在第13行上添加.. – sudheer

+0

因此您想根據子視圖更改第12行的高度? –

回答

1
NSArray *greenViewsIndexes=[NSArray arrayWithObjects:[NSNumber numberWithInt:5],[NSNumber numberWithInt:6],[NSNumber numberWithInt:11],[NSNumber numberWithInt:12], nil]; 
for (int i=0; i<24; i++) { 

for (int j=0; j>greenViews.count; j++) { 
if ([[greenViews objectAtIndex:j]intValue]==i){ 
    UIView *greenView=[[UIView alloc]initWithFrame:CGRectMake(71,61*(j+1),100,80)]; 
    [greenView setBackgroundColor:[UIColor greenColor]]; 
    } 
    } 

    //another operations 

} 
+0

很好的答案...但我只有兩個索引值5和11.當ia子視圖在索引5處添加80像素高度時,它必須與第6個索引重疊...但它沒有這麼做,因爲每行高度僅爲60像素....我想現在你得到了我的問題... – sudheer

+0

所以,你想添加子視圖與80高度60視圖,你不能改變視圖的高度60,對不對? – Kepler

+0

是的right.when我們通過80高度意味着添加子視圖必須在下一個子視圖上添加... – sudheer

0

我給你解決了問題。它不會與下一個單元格重疊,因爲您的下一個單元格位於您之前的單元格上並與之前單元格的邊緣重疊。嘗試:從超級視圖中刪除單元格(將具有綠色視圖),並再次添加綠色視圖:

NSArray *greenViewsIndexes=[NSArray arrayWithObjects:[NSNumber numberWithInt:5],[NSNumber numberWithInt:11], nil]; 
for (int i=0; i<greenViewsIndexes.count; i++) { 
int j=[[greenViewsIndexes objectAtIndex:i]intValue]; 
[[self.view subviews] objectAtIndex:i] removeFromSuperView] 

UIView *timeView=[[UIView alloc]initWithFrame:CGRectMake(71, 61*(j+1), 909, 60)]; //set your values 
timeView.userInteractionEnabled=TRUE; 
timeView.exclusiveTouch=YES; 
UIView *greenView=[[UIView alloc]initWithFrame:CGRectMake(71,61*(j+1),100,80)]; //set yourValues 
[greenView setBackgroundColor:[UIColor greenColor]]; 
[timeView addSubview:greenView]; 
[self.view addSubview:timeView]; 
} 
+0

感謝您的支持...我使用ios6.1。它顯示錯誤在removeFromSuperView .. – sudheer

+0

你是什麼得到,關於這個方法? – Kepler

相關問題