UITableView样式

UITableView样式

Table View Styles

There are two major styles of table views: plain and grouped. The two styles are distinguished mainly by appearance.

Plain Table Views

  • plain style:

    tableView = [[UITableView alloc]initWithFrame:XXX style:UITableViewStylePlain];

  • indexed list:

  • selection list:

Grouped Table Views

  • grouped style:

    tableView = [[UITableView alloc]initWithFrame:XXX style:UITableViewStyleGrouped];

Standard Styles for Table View Cells

  • Default table row style

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"XXX"];

  • Table row style with a right-aligned subtitle

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"XXX"];

  • Table row style in Contacts format

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"XXX"];

  • Table row style with a subtitle under the title

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"XXX"];

Accessory Views

1
2
3
4
5
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.accessoryType = UITableViewCellAccessoryDetailButton;

最后一个DetailButton是一个blue i
When you select a row in your table using didSelectRowAtIndexPath, you would set an @property to the object in your array that was selected: self.selectedObject = self.tableviewarray objectAtIndex:indexPath.row; Then in the prepareForSegue method you can get the destination view controller and do destinationViewController.myObject = self.selectedObject; Now the detail view knows what object to display info for!

UITableViewCellSeparatorStyle

  • UITableViewCellSeparatorStyleNone

    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

  • UITableViewCellSeparatorStyleSingleLine

    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

    The separator cell has a single line running across its width. This is the default value

  • UITableViewCellSeparatorStyleSingleLineEtched

    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;

    The separator cell has double lines running across its width, giving it an etched look. This style is currently only supported for grouped-style table views.