在tableview中减小部分的大小

问题描述:

我对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

- (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

嗨添加此的UITableViewDelegate方法

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

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

它的一个非常简单的SOLN ......上 “的UITableViewDelegate”

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

只需右键点击和“UITableViewDataSource”

n实现所有委托。 ..u会在那里找到所有类型的调整....天气你想改变或调整高度或宽度的部分或行...或多少部分或多少行在一个部分你想要.... 其简单的n自动调用....问候

+0

右击n去定义.... – namannam 2011-05-21 15:33:33