UITableView add buttons to section

I am new to iOS programming. I am creating an application for a course management system that has a tabular view for navigation to navigate between different courses. I want to add buttons to each section of the table instead of rows.

For example, if there are 5 elements in the CS101 course, I want 5 icons (UIButton's) to appear when I click on the CS101 heading located in 3 lines using the 2,2 and 1 buttons representing the five elements.

How should I do it? If possible?

Thank you so much! Satyam

+5
source share
2 answers

, . UITableView View TableView.

UITableView, .

:

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
 {
 // create the parent view that will hold header Label
 UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)];

 // create the button object
 UIButton * headerBtn = [[UIButton alloc] initWithFrame:CGRectZero];
 headerBtn.backgroundColor = [UIColor clearColor];
 headerBtn.opaque = NO;
 headerBtn.frame = CGRectMake(10.0, 0.0, 100.0, 30.0);
 [headerBtn setTitle:@"<Put here whatever you want to display>" forState:UIControlEventTouchUpInside];
[headerBtn addTarget:self action:@selector(ActionEventForButton:) forControlEvents:UIControlEventTouchUpInside];
 [customView addSubview:headerBtn];

 return customView;
 }

, , - 20., HEIGHT, .

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

, ...:)

+21

UIview , UIbutton

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

, , UIButton.

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
+1

All Articles