Illep
Illep

Reputation: 16859

UITableView adding grouped style and adding segments

I need to create a grouped tableview Controller some thing similar to this image

I have identified that this tableview has 2 segments, so i added 2 segments and 2 rows each for each segment.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

if(section == 0) return 2;
else return 2;
 }

1.) The problem i have is, how to add the Label on top of the 1st segment of the tableview.

I have to add 2 buttons in between the 2 Groups (tableviews), i know how to add one button, but how do you add 2 ?

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 0) {
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
       [button setTitle:@"Hello" forState:UIControlStateNormal];
       // How to add the 2nd button ?
       return button;
    }
     return nil;
 } 

3.) When i added the group table view with 2 segments, i didn't get the round edges in the cells, how do i get that ?

4.) I need to have the edit feature (so i could delete records) ONLY for the 2nd segment. So when i click on the edit button, i should be able to delete records only on the 2nd segment. Is this possible ? if so how do i do this ?

Upvotes: 2

Views: 792

Answers (2)

LJ Wilson
LJ Wilson

Reputation: 14427

  1. I assume you are talking about the Header for the Section? In that case, use the TableView delegate method titleForHeaderInSection

  2. Don't use the Footer to add the buttons. If you need buttons "in between the cells", just create a new section with no header title and one row to two rows and put the buttons as parts of the rows.

  3. Make sure you have the tableView style set properly:

    initWithStyle:UITableViewStyleGrouped];

  4. Use the tableview delegate method canEditRowAtIndexPath to allow/disallow editing (deleting) of a cell.

Upvotes: 1

Gabriel
Gabriel

Reputation: 3045

1) About the label, are you trying to add the label right above it, or directly on top of it? Try this, I'm not sure if the syntax is correct, but if you mess with it, it should work.

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, w, h)];
[titleLabel setText:@"TITLE"];
[**your UITableView** addSubview:titleLabel];
[self.view addSubview:**your UITableView**];
[titleLabel release];

3) the round edges... I'm not too sure about this, but it is either 1. your xcode version, maybe the round edges are in a newer/older version of xcode so you may have to upgrade... 2. In the example they are using a custom tableview that they made themselves, or its a different type of UITableView.

4) You can have a boolean function that checks for permissions, like if the user pressed one part or the other, the boolean function checks, this could be used to disable/enable the edit part of your function.

Upvotes: 0

Related Questions