Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Uiview UITableView分组样式_Uiview_Uitableview - Fatal编程技术网

Uiview UITableView分组样式

Uiview UITableView分组样式,uiview,uitableview,Uiview,Uitableview,我想创建一个分组表视图,如下所示 #pragma mark - Table view data source - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if(section == 0) return @"Countries to visit"; else return @"Countries visi

我想创建一个分组表视图,如下所示

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

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

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

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

您必须创建一个自定义UITableViewCell

这很好!在文字之后,你会建议如何使细胞像图片中的细胞那样变小!使用透明度管理框架?我建议你使用故事板,为此,谷歌是你的朋友,你会发现很多教程