UITableView分组样式

时间:2012-10-24 14:08:58

标签: uiview uitableview

我想制作一个分组表视图,如下面的

grouped table view

你有什么建议吗?我到目前为止所做的是一个分组的表视图,代码是下面的代码

#pragma mark - Table view data source

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(section == 0)
        return @"Countries to visit";
    else
        return @"Countries visited";
}

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
    //displays the header of the tableView
    self.tableView.tableHeaderView = view;

}

- (void) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{


    UIView *sectionHeader = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];

    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 100, 50)];

    textField.text = @"shit";

    [sectionHeader addSubview:textField];

    self.tableView.tableHeaderView = sectionHeader;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *CellIdentifier = @"ApplicationCell";

    ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[CompositeSubviewBasedApplicationCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                           reuseIdentifier:CellIdentifier];



    }
    // setting the background images for the selected and the normal actions!
    CGRect framme = cell.frame;

    UIImage *image = [UIImage imageNamed:@"buttonCellBackground_03.png"];
    UIImage *imageThumb = [UIImage imageNamed:@"buttonView.png"];
    UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
    [imageView setFrame:CGRectMake(framme.origin.x+29, 0, 290, 80)];
    [cell setBackgroundView:[[UIImageView alloc]initWithImage:imageThumb] ];
    [cell.backgroundView addSubview:imageView];


    UIImage *image2 = [UIImage imageNamed:@"ButtonViewSelected.png"];
    UIImage *imageThumb2 = [UIImage imageNamed:@"buttonView.png"];
    UIImageView* imageView2 = [[UIImageView alloc] initWithImage:image2];
    [imageView2 setFrame:CGRectMake(framme.origin.x+29, 0, 290, 80)];
    [cell setSelectedBackgroundView:[[UIImageView alloc]initWithImage:imageThumb2] ];
    [cell.selectedBackgroundView addSubview:imageView2];

return cell;
}

标题我想包含标题和背景?

1 个答案:

答案 0 :(得分:0)

您必须创建自定义UITableViewCell