• 应用程序之淘宝商城界面模拟


    • 效果展示
    • 代码实现

    一、效果展示

    二、代码实现

    1⃣️数据源

    2⃣️代码实现

    //
    //  ViewController.m
    //  03-淘宝商品001
    //
    //  Created by apple on 14-4-3.
    //  Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "Shops.h"
    
    @interface ViewController () <UITableViewDataSource, UITableViewDelegate>
    {
        NSMutableArray *shopArray;
        NSMutableArray *selectShop;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *path = [bundle pathForResource:@"shops" ofType:@"plist"];
        NSArray *tempArray = [NSArray arrayWithContentsOfFile:path];
        shopArray = [NSMutableArray array];
        selectShop = [NSMutableArray array];
        
        for (NSDictionary *dict in tempArray) {
            Shops *shop = [Shops showWithDict:dict];
            [shopArray addObject:shop];
        }
    }
    //得到cell个数
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        if (selectShop.count == 0) {
            _titleLable.text = @"淘宝";
            _removeItem.enabled = NO;
        } else {
            _titleLable.text = [NSString stringWithFormat:@"淘宝(%d)", selectShop.count];
            _removeItem.enabled = YES;
        }
        return shopArray.count;
    }
    //刷新cell
    -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        Shops *shop = shopArray[indexPath.row];
        
        static NSString *cellIndentifier = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier];
        }
        cell.textLabel.text = shop.title;
        cell.detailTextLabel.text = shop.desc;
        cell.imageView.image = [UIImage imageNamed:shop.icon];
        
        if ([selectShop containsObject:shop]) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        } else {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        
        return cell;
    }
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //取消选中时的蓝色
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        
        Shops *shop = shopArray[indexPath.row];
        
        if ([selectShop containsObject:shop]) {
            [selectShop removeObject:shop];
        } else {
            [selectShop addObject:shop];
        }
        
        [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
    }
    
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 70;
    }
    
    -(void)deleteCell
    {
        [shopArray removeObjectsInArray:selectShop];
        
        [selectShop removeAllObjects];
        
        [self.tableView reloadData];
    }
    @end
  • 相关阅读:
    Splay板子
    HZOI帝国2019欢乐时刻
    数据分析体系 — 用户粘性的两个计算指标(DAU/MAU和月人均活跃天数)
    mysql—MySQL数据库中10位时间戳转换为标准时间后,如何对标准时间进行加减X天处理
    每日一题力扣575 分糖果
    每日一题力扣455 小饼干和孩子
    每日一题力扣561
    每日一题力扣121 最佳买股票
    每日一题力扣605 种花问题
    每日一题力扣605 种花问题
  • 原文地址:https://www.cnblogs.com/letougaozao/p/3652720.html
Copyright © 2020-2023  润新知