Search code examples
iosobjective-cuitableviewuislider

Recreating and understanding iOS settings menu


I would like to recreate the iOS settings menu. To do so I need to understand how this is created. Please find an example here below:

enter image description here

My understanding is that this is a masterdetailview controller style project with at the left a table view and at the right a detail view with custom cells.

I found this answer to recreate the grouping but have no idea yet on how to create the custom actions.

  • How can I create a custom cell like the one below to adjust brightness (it has a slider)?
  • How do you add a label like Apple does and a button? Do you have a separate xib file for each cell?

Solution

  • To add a custom UITableViewCell you should have a UITableView in your ViewController.

    Then you can add Custom UITableViewCell by Adding a new file to the project.

    enter image description here

    Now you can see 3 files are added to the project. Go to the XIB file & modify it as you want. Finally Go to the

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  method & add these lines in it.
    
    static NSString *MyIdentifier = @"MyIdentifier"; //Set Identifier for cell
    
            CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: MyIdentifier]; //init CustomCell
    
            if (cell == nil) { //Check cell is nill or not
                NSArray *nib;
                nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell"
                                                    owner:self options:nil]; //if cell is nil add CustomCell Xib
    
                for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]])
                    cell = (CustomCell *)oneObject;
            }
    
            //Set Cell Values Here
    
            return cell;