// 設(shè)置cell右邊的指示樣式(箭頭樣式)
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// 設(shè)置cell右邊顯示的控件
// accessoryView優(yōu)先級 > accessoryType
cell.accessoryView = [[UISwitch alloc] init];
// 去除多余的分割線
self.tableView.tableFooterView = [[UIView alloc] init];
// 隱藏狀態(tài)欄
- (BOOL)prefersStatusBarHidden {
return YES;
}
// 快速計(jì)算位置
CGFloat titleX = CGRectGetMaxX(self.iconImageView.frame) + space;
CGFloat priceY = CGRectGetMaxY(self.iconImageView.frame) - space;
// xib 加載自定義cell
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([XMGTgCell class]) owner:nil options:nil] lastObject];
}
// 代碼注冊cell
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuse];
// xib注冊
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([UITableViewCell class]) bundle:nil] forCellReuseIdentifier:reuse];
- 利用MJExtension將數(shù)據(jù)轉(zhuǎn)模型
@property (nonatomic, strong) NSArray *statuses;
// 利用MJExtension將數(shù)據(jù)轉(zhuǎn)模型
// 懶加載
- (NSArray *)statuses {
if (!_statuses) {
_statuses = [XMGStatus mj_objectArrayWithFilename:@"statuses.plist"];
}
return _statuses;
}
- 計(jì)算文字的尺寸(不需要換行)

計(jì)算Lable內(nèi)文字的尺寸.png
// self--sizing(iOS8 以后)
// 告訴tableView所有cell的真實(shí)高度是自動計(jì)算的(根據(jù)設(shè)置的約束)
self.tableView.rowHeight = UITableViewAutomaticDimension;
// 設(shè)置估算高度
self.tableView.estimatedRowHeight = 44;

屏幕快照 2016-08-03 下午8.28.26.png
-
iOS8之前必須計(jì)算:heightForRowAtIndexPath:代理方法中
屏幕快照 2016-08-03 下午8.45.24.png
XMGStatusCell *cell; // 定義一個(gè)全局變量(因?yàn)檫@是一個(gè)打醬油的cell)
// 創(chuàng)建一個(gè)臨時(shí)的cell
if (cell == nil) {
cell = [tableView dequeueReusableCellWithTdentifier:ID];
}
// 修改模型:數(shù)據(jù)源
XMGWine *wine = self.wineArray[0];
wine.money = @"¥100";
// 告訴tableView數(shù)據(jù)變了,趕緊刷新
// 全局刷新
[self.tableView reloadData];
// 局部刷新
NSArray *indexPath = @[[NSIndexPath indexPathForRow:0 inSection:0]];
// 使用前提:保證數(shù)組的個(gè)數(shù)不變
[self.tableView reloadRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationLeft];
// 插入
[self.tableView insertRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationRight];
// 刪除
[self.tableView deleteRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationMiddle];
// 退出編輯模式(右側(cè)編輯按鈕,平滑退出)
self.tableView.editing = NO;
// 進(jìn)入編輯模式
// self.tableView.editing = !self.tableView.isEditing; // 無動畫效果
[self.tableView setEditing:!self.tableView.isEditing animated:YES]; // 帶有動畫效果
self.deletedButton.hidden = !self.tableView.isEditing;
// 告訴tableView在編輯模式下可以多選
self.tableView.allowsSelectionDuringEditing = YES;
- 千萬不要一邊遍歷一邊刪除,因?yàn)槊縿h除一個(gè)元素,其他元素的索引可能會發(fā)生變化
NSMutableArray *deletedWine = [NSMutableArray array];
for (NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows) {
[deletedWine addObject:self.wineArray[indexPath.row]];
}
// 修改模型
[self.wineArray removeObjectsInArray:deletedWine];
// 刷新表格
// [self.tableView reloadData];
[self.tableView deleteRowsAtIndexPaths:self.tableView.indexPathsForSelectedRows withRowAnimation:UITableViewRowAnimationAutomatic];
// 取消選中狀態(tài)(在代理方法didSelectRowAtIndexPath:中寫)
[tableView deselectRowAtIndexPath:indexPath animated:YES];
