2011-05-21 33 views
0

我對iphone開發非常陌生,我想減小分組表格視圖中的部分大小,即減小部分的寬度。怎麼能提前實現 感謝在tableview中減小部分的大小

+0

你試過減少整個tableview的寬度? – 2011-05-21 11:39:09

+0

@Nick Weaver:實際上我也不知道,我也想這樣做的部分和表格視圖 – sujay 2011-05-21 11:40:47

+0

你可以用'myTableView.frame = CGRectMake(x,y,width,height)設置整個tableView的大小);'。您必須調整CGRectMake的值。該部分應該相應縮小。請嘗試一下,告訴我們是否適合您的需求。 – 2011-05-21 11:43:45

回答

2
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
    return kHeightForHeaderInSection; 
} 


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
     // wrapperView - by default has the width of the table, you can change the height 
     // with the heightForHeaderInSection method 
     UIView *aView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 

     // your real section view: a label, a uiview, whatever 
     CGRect myFrame; // create your own frame 
     myFrame.origin = CGPointMake(10, 0); 
     myFrame.size = CGSizeMake(tableView.bounds.size.width-10,kHeightForHeaderInSection); 
     UILabel *label = [[[UILabel alloc] initWithFrame:myFrame] autorelease]; 
     label.text = @"myText" 
     [aView addSubview:label]; 

     return aView; 
    } 
+0

可否請您詳細說明您的上述方法,我沒有得到它.. – sujay 2011-05-21 12:14:50

+0

在您的tableView委託中您需要實現上述方法。 viewForHeaderInSection返回一個視圖(讓我們調用myView),其高度等於heightForHeaderInSection返回的值,width等於tableView寬度。在這一點上,你可以創建和添加你自己定義的框架的目標視圖(即標籤),並將其添加到myView。另一種方法是繼承UILabel方法: - textRectForBounds:limitedToNumberOfLines:和-drawTextInRect :. – marcio 2011-05-21 14:06:29

0

嗨添加此的UITableViewDelegate方法

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return height; 
} 
+0

我想設置寬度每一行都不是高度.. – sujay 2011-05-21 12:19:09

0

它的一個非常簡單的SOLN ......上 「的UITableViewDelegate」

@interface MyController : UIViewController <UITableViewDelegate, UITableViewDataSource> 
{ 
IBOutlet UITableview *myTableview; 

只需右鍵點擊和「UITableViewDataSource」

n實現所有委託。 ..u會在那裏找到所有類型的調整....天氣你想改變或調整高度或寬度的部分或行...或多少部分或多少行在一個部分你想要.... 其簡單的n自動調用....問候

+0

右擊n去定義.... – namannam 2011-05-21 15:33:33