官方文档介绍
Default,// Simple cell with text label and optional image view
(behavior of UITableViewCell in iPhoneOS 2.x)
Value1, // Left aligned label on left and right aligned label on
right with blue text (Used in Settings)
Value2, // Right aligned label on left with blue text and left
aligned label on right (Used in Phone/Contacts)
Subtitle,// Left aligned label on top and left aligned label on
bottom with gray text (Used in iPod).
value1:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];
value2:(我个人是很少用到)
image.png
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];
subtitle:
image.png
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];
default:
image.png
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];
tip: UITableViewCell里面还有很多属性 比如cell.accessoryView = [[UISwitch alloc]init]效果如图。如果你想做好几个控件放accessoryView,那就用UIView包着cell.accessoryView =UIView
image.png
cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像>素;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;
cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;
网友评论