Built-in UITableViewCell's Styles (UITableViewCellStyle)

UITableView has some built-in styles which can be use with in most scenario. You might want to look into these styles before starting to built a customize TableViewCell.

There are 4 types of styles for the UITableViewCell, enum representation of this is UITableViewCellStyle. The details is as follow:

  •  UITableViewCellStyleDefault, Default style with label on the left. 
  •  UITableViewCellStyleValue1, Label on the left, and a blue label on the right. 
  •  UITableViewCellStyleValue2, Blue label on the left side (right aligned text), label on the right side (left aligned text). 
  •  UITableViewCellStyleSubtitle, This is almost same with the Default style except that it has a grey smaller text under the label. It functions as the description / subtitles.
To change the default style of a UITableViewCell, replace the styles enum in initWithStyle with any of the enum mentioned above, simple as that. Example:


// ObjC version

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                      reuseIdentifier:CellIdentifier];
    }
    
    // Configure the cell...
    return cell;
}

// Swift version

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
    let cellIdentifier = "Cell"
    var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as UITableViewCell

    if !cell {
        cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellIdentifier)
    }

    // Configure the cell...
    return cell
}

Comments

  1. Very useful reference

    ReplyDelete
  2. Detox drinks for THC Detox kit work by diluting your urine in the body itself to the point that you have a very low concentration of THC; giving your body a window during which you can pass the test. Detox pills, on the other hand, actually speed up your body metabolism rate to rid of toxins from your system. So, if you’ve got the extra time, the answer is simple: use detox pills instead. They’ll give you a much better chance of passing the test. One of the best detox shampoos in the market is the Old Style Aloe Toxin Rid Shampoo. You may want to begin by washing your hair with the detox shampoo at least 3 – 10 days before the drug test. Visit: https://www.urineworld.com/

    ReplyDelete
  3. PokerStars - Titanium App - TITanium-Art
    In-depth review titan metal of titanium granite PokerStars titanium steel including poker games, mens titanium wedding bands bonuses, latest promotions, software, banking, limits and more. titanium security

    ReplyDelete
  4. Thank You and that i have a super offer: Where Is Charlotte Church House Renovation remodeling companies near me

    ReplyDelete

Post a Comment

Popular posts from this blog

Generating INSERT statement from SELECT using SQuirreL SQL

OneNote: We need the password to sync this notebook (Error code: 0xE4010643)