3

I am trying to implement one feature:

enter image description here

Image 1 show headers with titles. When you click on header 1,2,3,4 it will expand and shows tableview rows like shown in image 2.

What I want is that at header 0 view, I want to customize and wants to add an image and some text (see image 3).

How to achieve this feature, how can I can I customize tableview header using Objective-C?

I used below code but not showing any changes,

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
    /* Create custom view to display section header... */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
    [label setFont:[UIFont boldSystemFontOfSize:12]];
     NSString *string =[list objectAtIndex:section];
    /* Section header is in 0th index... */
    [label setText:string];
    [view addSubview:label];
    [view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
    return view;
}

Here is my project sample

Priyanka Patil
  • 318
  • 1
  • 9
  • Do same as cell – SPatel May 29 '18 at 04:11
  • Image 2 is created by me, I want to create a header view. Rest thing is done, only that one part is left. – Priyanka Patil May 29 '18 at 04:31
  • See this link, http://www.iostute.com/2015/04/expandable-and-collapsable-tableview.html. Here in this viewForHeaderInSection: function they implemented some views and superator line like this you also do the same thing. – Naresh May 29 '18 at 04:59

1 Answers1

1

user the viewForHeaderInSection method . It returns a UIView. You could create your desired UIView() programatically. I assume you know how to do that.

Now, in this method check the indexPath.row. IF its "0" then your ImageView Should return ...else return some other view such as a label with a certain text. Hope it helps.

Zahurafzal Mirza
  • 290
  • 1
  • 15