反正我是发现目前好多apps都需要有这样的功能。希望大家可以受用吧。其实这样的cell的思路我有两个:1.在cell上加手势,2.使用系统自带的(iOS8.0之后更新的)。思路一得具体实现我就不多讲了,在我的代码里有,只是注释了,可以供大家参考一下。我们来讲思路二。
首先,在STB中自定义一个主页的cell,大致如下:
我这里取名叫yxHomeTableViewCell。同时我模拟了一个网络请求:
+ (RACSignal *)signalForApi:(NSString *)api withParameter:(NSDictionary *)para {
NSDictionary *dict = @{@"data":@[@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhegaskjlksajlkajslk;jaslkj可能大量客户的数量可费劲了;卡e shi yige ceshi xiaoxi ",@"img":@"2",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"3",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"4",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"5",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"6",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"7",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"8",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"9",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"10",@"time":@"14:38"}]};
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSMutableArray <yxHomeTableViewCellModel *> *dataSource = [NSMutableArray array];
for (id obj in dict[@"data"]) {
[dataSource addObject:[yxHomeTableViewCellModel modelWithDictionary:obj]];
}
[subscriber sendNext:dataSource];
[subscriber sendCompleted];
});
return [RACDisposable disposableWithBlock:^{
}];
}];
return signal;
}
很显然,我们回到yxHomeViewController.m后实现tableView的dataSource,你会得到这样的效果:
下面就是添加侧滑了。事实上,在iOS8.0以后,系统公布了一个api,可以让我们快速的添加上这些cell的按钮:
#pragma mark - UITableViewDelegate
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction * action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
}];
action.backgroundColor = [UIColor redColor];
UITableViewRowAction * action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"标为未读" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
}];
action1.backgroundColor = [UIColor lightGrayColor];
return @[action,action1];
}
效果如下:
是不是很简单!(关于MVC的我就不多讲了)。
ps:今天就到这里,其实项目中简单的页面就不用我多说了,就是几个tableView而已,目前正在写朋友圈里的东西,到时候就会有比较多的文字了,请亲们期待一下咯!!!