2014-06-05 31 views
0

我在視圖控制器中有兩個uitableviews。第一個表以編程方式設置在uiscrollview上,另一個表在storyboard上的self.view中設置。我已經將tableHeight設置爲45.但是隨着行數的增加,我逐漸增加了一張桌子的高度,就像我所顯示的截圖一樣。uitableview的行高逐漸不同

Screen shot 1

Screen shot 2

代碼是這樣的:

scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(130, 45, self.view.frame.size.width-130, self.view.frame.size.height-45)]; 
    scrollview.backgroundColor = [UIColor colorWithRed:0.42 green:0.27 blue:0.60 alpha:1.0]; 
    tableGradeValue = [[UITableView alloc] initWithFrame:CGRectMake(0, 35, self.view.frame.size.width, self.view.frame.size.height-75) style:UITableViewStylePlain]; 
    tableGradeValue.delegate = self; 
    tableGradeValue.dataSource = self; 
    self.tableCourse.delegate = self; 
    self.tableCourse.dataSource = self; 
    tableGradeValue.rowHeight = 45; 
    scrollview.bounces = NO; 

    for(int i = 0; i< [res6Keys count]; i++) 
    { 
     CGFloat y = i * 150; 
     UILabel *lblCell = [[UILabel alloc] initWithFrame:CGRectMake(y, 1, 140, 31)]; 
     lblCell.tag = i+1; 
     [scrollview addSubview:lblCell]; 
     lblCell.backgroundColor = [UIColor clearColor]; 
     lblCell.textColor = [UIColor colorWithRed:0.93 green:0.92 blue:0.96 alpha:1.0]; 
     lblCell.text = [res6Keys objectAtIndex:i]; 
    } 
    [scrollview addSubview:tableGradeValue]; 
    scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height); 
    [self.view addSubview:scrollview]; 

而其他實現代碼如下從故事板通常設置和rowHeight的是45

+1

UITableview從scrollview繼承,所以你爲什麼把它放在scrollview上。真的沒有得到那個?! – nikhil84

+0

因爲scrollview上的tableview可以水平和垂直滾動,頂部有一個標題行,它不是tableview的一部分,但仍然保持在scrollview上,但仍然與表格一起水平滾動,因此它提供了一個MSExcel看。 –

+0

@LeoJoseph你可以請張貼一些代碼,以更好地瞭解你哪裏出錯了? – z22

回答

0

我不知道這是問題所在。但奇怪的是我得到了答案。我將@property和@synthesis分配給滾動視圖上的表格。我現在給財產和綜合,它開始工作。

+0

'@ synthesis' ...??你從哪裏得到這個? – holex

+0

\ @屬性(強,非原子)UITableView * tableGradeValue; \ @synthesize tableGradeValue; –

+0

是的,'@ synthesisize'和'@ synthesis'絕對不一樣。第一個是一個正確的關鍵字,第二個只是在_Objective-C_中從來沒有的東西。 – holex