2013-01-23 32 views
1

我试图把两个不同类型的数据之间的能指之间被馈入我的动态UITableView。我允许将数据拆分为两部分,还是只需要在非userInteractionEnabled单元格中添加以标记拆分?我无法以编程方式设置numberOfSections属性。有谁知道如何解决这个问题?你可以将一个动态UITableView分割成几个部分吗?

+1

是的,它被称为分组的tableview把部分' - (NSInteg呃)numberOfSectionsInTableView:(UITableView *)tableView {0}返回2; }'到你的tableview,看看http://www.mobisoftinfotech.com/blog/iphone/iphone-uitableview-tutorial-grouped-table/ –

+0

为什么你不能设置'numberOfSections'? –

+0

@SpaceDust,你应该添加它作为答案。 – iDev

回答

1

你所试图做的是建立一个分组表视图,请确保您的界面生成器您选择分组的tableview选项为您的表视图

然后调用分组表视图的方法,如

// for sections I guess you want 2 sections 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 
    if(section==0) 
     return [yourdatasource count]; // make sure that each section is returned here 
    if(section==1) 
     return [anotherdatasource count]; 
} 

// set header height of gropued tableview 
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section { 

    return 60.0; // choose your height for each section 
} 
//set header section labels 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
} 

我的代码没有经过测试,

看这个http://www.mobisoftinfotech.com/blog/iphone/iphone-uitableview-tutorial-grouped-table/进一步信息

相关问题