TableView 实现京东购物车功能
来源:互联网 发布:记账软件 编辑:程序博客网 时间:2024/05/01 13:04
2、设置编辑按钮
//编辑按钮
self.enditButton = [[UIBarButtonItem alloc] initWithTitle:@"删除" style:UIBarButtonItemStylePlain target:selfaction:@selector(editButtonDidClick:)];
self.navigationItem.rightBarButtonItem = self.enditButton;#pragma mark - 删除按钮点击事件
- (void)editButtonDidClick:(UIBarButtonItem *)editButton
{
//设置编辑状态
if (self.tableView.editing == YES) {
[editButton setTitle:@"删除"];
[self.tableView setEditing:NO animated:YES];
}else
{
[editButton setTitle:@"取消"];
[self.tableView setEditing:YES animated:YES];
}
if (self.tableView.editing) {
if (self.deleteButtonBack == nil) {
self.deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(18, 15, YJScreenWidth - 30, 40)];
[self.deleteButton setTitle:@"删除" forState:UIControlStateNormal];
[self.deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.deleteButton setBackgroundColor:YJColorRGBA(242, 48, 48, 1)];
self.deleteButton.layer.cornerRadius = 3;
self.deleteButton.layer.masksToBounds = YES;
[self.deleteButton addTarget:self action:@selector(deleteButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
if ([self.isMoreInput isEqualToString:@"YES"]) {
self.deleteButtonBack = [[UIView alloc] initWithFrame:CGRectMake(0, YJScreenHeight - 57, YJScreenWidth, 75)];
}else{
self.deleteButtonBack = [[UIView alloc] initWithFrame:CGRectMake(0, YJScreenHeight - 57 - 44, YJScreenWidth, 75)];
}
self.deleteButtonBack.backgroundColor = [UIColor whiteColor];
[self.deleteButtonBack addSubview:self.deleteButton];
[self.view addSubview:self.deleteButtonBack];
[self.view bringSubviewToFront:self.deleteButton];
[UIView animateWithDuration:0.25 animations:^{
self.deleteButtonBack.transform = CGAffineTransformMakeTranslation(0, -75);
editButton.enabled = NO;
} completion:^(BOOL finished) {
editButton.enabled = YES;
if ([self.isMoreInput isEqualToString:@"YES"]) {
self.tableVonstraint.constant = 70;
}else{
self.tableVonstraint.constant = 110;
}
}];
}
}else
{
self.tableVonstraint.constant = 0;
if (self.deleteButtonBack != nil) {
[UIView animateWithDuration:0.25 animations:^{
self.deleteButtonBack.transform = CGAffineTransformIdentity;
editButton.enabled = NO;
} completion:^(BOOL finished) {
[self.deleteButtonBack removeFromSuperview];
self.deleteButtonBack = nil;
editButton.enabled = YES;
}];
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
/**
* 删除按钮点击事件
*
* @param deleteButton 删除按钮
*/
- (void)deleteButtonDidClick:(UIButton *)deleteButton
{
}
#pragma mark - TableViewDelegate
//选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MoreCollectionModel * model = self.dataSourceArray[indexPath.section];
if (indexPath.row == 0) {
for (int i = 0; i < model.goodsArray.count; i++) {
NSIndexPath * index = [NSIndexPath indexPathForRow:i + 1 inSection:indexPath.section];
[tableView selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];
}
}else
{
NSArray * indexArray = [tableView indexPathsForSelectedRows];
NSInteger indexCount = 0;
for (NSIndexPath * index in indexArray) {
if (index.section == indexPath.section) {
indexCount ++;
}
}
if (indexCount == (model.goodsArray.count)) {
[tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:indexPath.section] animated:YESscrollPosition:UITableViewScrollPositionNone];
}
}
NSArray * array = [self.tableView indexPathsForSelectedRows];
[self.indexPaths addObjectsFromArray:array];
}
//取消选中
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
MoreCollectionModel * model = self.dataSourceArray[indexPath.section];
if (indexPath.row == 0) {
for (int i = 0; i < model.goodsArray.count; i++) {
NSIndexPath * index = [NSIndexPath indexPathForRow:i + 1 inSection:indexPath.section];
[tableView deselectRowAtIndexPath:index animated:YES];
}
}else
{
NSArray * indexArray = [tableView indexPathsForSelectedRows];
NSInteger indexCount = 0;
for (NSIndexPath * index in indexArray) {
if (index.section == indexPath.section) {
indexCount ++;
}
}
if ((indexCount - 1) != (model.goodsArray.count)) {
[tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:indexPath.section] animated:YES];
}
}
NSArray * array = [self.tableView indexPathsForSelectedRows];
[self.indexPaths removeObjectsInArray:array];
}
4、效果如下图:- TableView 实现京东购物车功能
- 购物车实现功能
- 购物车功能实现
- 购物车功能实现
- 购物车功能实现
- PHP实现购物车功能
- 加入购物车功能实现
- javase实现购物车功能
- jQuery实现购物车功能
- 购物车功能如何实现
- angular实现购物车功能
- yii2 实现购物车功能
- 购物车实现功能1
- 购物车实现功能2
- RecyclerView 实现购物车功能
- Android实现购物车功能
- 实现简单购物车功能
- angularJS实现购物车功能
- 操作系统之银行家算法
- 数据结构之堆(Heap)的实现
- 找出N个数据中的最大的K个数据---堆排序
- 优先级队列
- 斐波那契数列的最优算法(O(logN))
- TableView 实现京东购物车功能
- 在网页上显示当前日期
- 类模板的分离编译
- 处理哈希冲突的线性探测法
- 模拟实现英汉字典(使用key/value形式的哈希表)
- 实现哈希桶(空间利用率较高的哈希表)
- [hadoop]hadoop2.x(七)
- 复习二进制位的一些操作
- 多态的说明