-1

I have table view , I want to display events according to time. Suppose I have 2 events at 3 PM then I need section header 3 PM and in that two rows with event title.

enter image description here

In Above dummy image There are 2 sections (3:00 PM and 7:00 PM)with respective events. and table header is Date.

I have worked on Table view but without sections. Please help me to achieve this.

Raj
  • 637
  • 13
  • 32

1 Answers1

1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return how many section you need
}

//Set your section header height

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0f;
}

//Set your section view

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tblImageList.frame.size.width, 40)];
   [vw setBackgroundColor:[UIColor clearColor]];
   UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tblImageList.frame.size.width, 40)];
   [lbl setText:@"your text"];
   [lbl setBackgroundColor:[UIColor clearColor]];
   [lbl setTextColor:[UIColor colorWithRed:45.0f/255.0f green:206.0/255.0f blue:189.0f/255.0f alpha:1.0f]];
   [vw addSubview:lbl];

   return vw;

}

BHASKAR
  • 1,201
  • 1
  • 9
  • 20