0

我想制作一个像下面这样的分组表视图

分组表视图

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

#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;
}

我猜标题将包含标题和背景?

4

1 回答 1

0

您必须创建一个自定义 UITableViewCell

于 2012-10-24T15:33:53.393 回答