2012-10-24 70 views
0

我想要像下面的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; 
} 

我想將包含標題和背景的頭一個?

回答

0

你必須創建一個自定義的UITableViewCell

+0

多數民衆贊成好!之後的話會如何建議使像細胞一樣小的圖片!使用透明度來管理框架? – Filip

+0

我建議你使用故事板,爲此,谷歌是你的朋友,你會發現很多教程 – Solidus

+0

感謝兄弟!是的,我已經GOOGLE了 – Filip