//
// TableViewController.m
#import "TableViewController.h"
#import "tgModel.h"
#import "tgCell.h"
@interface TableViewController ()
/** 所有团购数据 */
@property(nonatomic,strong) NSMutableArray *tgs;
@end
@implementation TableViewController
- (NSMutableArray *)tgs
{
if (_tgs == nil) {
// 加载plist文件中的字典数组
NSString *path = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil];
NSArray *dictArray = [NSArray arrayWithContentsOfFile:path];
// 字典数组 -> 模型数组
NSMutableArray *arrayM = [NSMutableArray array];
for (NSDictionary *dict in dictArray) {
tgModel *model = [tgModel tgWithDict:dict];
[arrayM addObject:model];
}
_tgs = arrayM;
}
return _tgs;
}
- (void)viewDidLoad {
[super viewDidLoad];
// //注册xib
// UINib *nib = [UINib nibWithNibName:NSStringFromClass([tgCell class]) bundle:nil];
// [self.tableView registerNib:nib forCellReuseIdentifier:@"cell"];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.tgs.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 创建cell的过程封装到cell类中
tgCell *cell = [tgCell cellWithTableView:tableView];
//传递模型数据
cell.model = self.tgs[indexPath.row];
return cell;
}
#pragma mark - 代理方法
/**
* 只要实现这个方法,左滑cell就会出现删除按钮的功能就有了
*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
//删除模型
[self.tgs removeObjectAtIndex:indexPath.row];
//刷新表格
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
@end
UITableViewCell上左滑删除
最新推荐文章于 2021-12-22 09:16:15 发布
本文介绍了一个iOS应用中如何使用Table View展示从plist文件加载的数据,并实现了数据模型与单元格的绑定及删除功能。文章详细讲解了如何将plist文件中的字典数组转换为模型数组,以及如何通过自定义的单元格类来展示数据。
1664

被折叠的 条评论
为什么被折叠?



