2

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 ?

Illep
  • 16,375
  • 46
  • 171
  • 302
  • 1
    Here's the class reference, press ctrl+f and type in grouped, then press enter. You'll see some documentation on the table... http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html – Gabriel Dec 20 '11 at 16:53
  • 2
    Your answer is not helpful. Thank you anyway i have already browsed through it! – Illep Dec 20 '11 at 16:56
  • @lllep which is why its a comment, and not an answer ^_^ – Gabriel Dec 20 '11 at 16:57
  • @Gabe oh! yeah sorry about it :D – Illep Dec 20 '11 at 16:59
  • @lllep its all good, I would have helped more with your question but there's more than just one thing being asked... and the question confused me a bit. – Gabriel Dec 20 '11 at 17:01
  • @Gabe it would be great if you could at least help me solve one of those questions. i have read the documentation and its a too complicated to a beginner like me. – Illep Dec 20 '11 at 17:08
  • @lllep TBH I'm pretty new also, but I'll see what I can do – Gabriel Dec 20 '11 at 17:09

2 Answers2

1
  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.

LJ Wilson
  • 14,445
  • 5
  • 38
  • 62
  • This is about question 2. Imagine i have 3 segments, and i have a fix amount of cells in the 1st two sections. The 3rd section there might be alot of cells. So i would need to scroll the view to get down. and again about question 4, i only need to delete rows from the 3rd section, so can this be done using canEditRowAtIndexPath ? What i want to do is to Add a scroll only to the 3rd Segment and keep the remaining to segments un-scrollable. Is this possible ? – Illep Dec 20 '11 at 20:00
  • Can you show me a sample code how to add 2 buttons to titleForHeaderInSection. i was able to add 1 button to the viewForFooterInSection. But was not able to add 2 buttons – Illep Dec 20 '11 at 20:02
  • You cannot do this easily(I don't know of any way). That said, you can have two distinct TableViews in one view, but you need to outsource the datasource and delegate methods. Check out this SO post: http://stackoverflow.com/questions/254354/uitableview-issue-when-using-separate-delegate-datasource – LJ Wilson Dec 20 '11 at 21:47
  • For the sample code question, you don't need to use titleForHeaderInSection (that is supposed to return an NSString). You need to put those buttons in a cell(s). – LJ Wilson Dec 20 '11 at 21:49
0

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.

Gabriel
  • 3,039
  • 6
  • 34
  • 44