在UITableView中,我们有头
例如
假设我想要根据企业所在的建筑对企业进行分组。
BuildingA 10 Business1 Business2 Business3 Business4
我如何排列使10在标题的右侧
发布于 2012-01-26 12:33:20
您可以覆盖tableView:viewForHeaderInSection:以添加您自己的额外标签,该标签的矩形位于右侧某处,如CGRectMake(280,5,30,20);。您还应该设置它,以便文本右对齐。
请注意,如果这样做,还必须提供左侧标签(因为它已经不在那里了),并且还必须覆盖tableView:heightForHeaderInSection:。
发布于 2012-01-27 21:31:30
因为用户可以使用自定义标题单元格,然后该单元格附加在标题中。
为此,实现了以下代码。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 2;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *v=[[[NSBundle mainBundle] loadNibNamed:@"tHeader" owner:self options:nil] objectAtIndex:0];
[(UILabel*)[v viewWithTag:1] setText:[NSString stringWithFormat:@"%i",section+1]];
return v;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return (section==0)?5:((section==1)?7:((section==2)?3:4));
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[NSString stringWithFormat:@" Hello-%i",indexPath.row];
// Configure the cell.
return cell;
}download source from here.
https://stackoverflow.com/questions/9013942
复制相似问题