//
// ViewController.m
// 0429
//
// Created by apple on 15/4/29.
// Copyright (c) 2015年 gense. All rights reserved.
// #import "ViewController.h"
#import "ProductCategory.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSMutableArray * productCategoryList ;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; //从配置文件中初始化商品类型信息
[self initProudctCategory]; } #pragma mark 从配置文件中初始化商品类型信息
- (void) initProudctCategory
{
//读取参数文件
NSString * paramPath = [[NSBundle mainBundle] pathForResource:@"shops.plist" ofType:nil];
NSArray * dataArr = [NSArray arrayWithContentsOfFile:paramPath]; productCategoryList = [NSMutableArray arrayWithCapacity:10]; //遍历plist文件
[dataArr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[productCategoryList addObject: [ProductCategory productCategoryWithName:obj[@"name"] andDesc:obj[@"desc"] icon:obj[@"icon"]]];
}]; } #pragma mark tableviewDeleage 总共有多少行记录
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [productCategoryList count];
} #pragma mark 实例化每行cell
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellIdentified = @"productCategoryTableViewCell"; //从缓存中加载可用的cell
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentified]; if(cell == nil) //从缓存在未拿到合适的cell
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentified]; } //设置cell中的属性
cell.textLabel.text = [productCategoryList[indexPath.row] name];
cell.detailTextLabel.text = [productCategoryList[indexPath.row] desc]; cell.imageView.image = [UIImage imageNamed:[productCategoryList[indexPath.row] icon]]; if([productCategoryList[indexPath.row] isSelected])
{
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}
else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
} return cell;
} #pragma mark 设置tableview每行的高度 - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[productCategoryList[indexPath.row] setIsSelected: ![productCategoryList[indexPath.row] isSelected ]]; [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } #pragma mark 滑动删除
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(UITableViewCellEditingStyleDelete == editingStyle)
{
[productCategoryList removeObjectAtIndex:indexPath.row]; //[_productCategoryTV reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop]; [_productCategoryTV deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
}
} #pragma mark 拖动排序
-(void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
ProductCategory * p = productCategoryList[sourceIndexPath.row]; [productCategoryList removeObject:p]; [productCategoryList insertObject:p atIndex:destinationIndexPath.row]; } #pragma mark 删除选中的数据
- (IBAction)trashItemClick:(id)sender
{
// NSMutableArray * deleteArr = [NSMutableArray arrayWithCapacity:10];
// NSMutableArray * indexPathArr = [NSMutableArray arrayWithCapacity:10 ];
//
// [productCategoryList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// if([obj isSelected])
// {
// [deleteArr addObject:obj];
// [indexPathArr addObject:[NSIndexPath indexPathForItem:idx inSection:0]];
// }
// }];
//
// [productCategoryList removeObjectsInArray:deleteArr];
//
// //tableview reload
// [_productCategoryTV deleteRowsAtIndexPaths:indexPathArr withRowAnimation:UITableViewRowAnimationMiddle];
_productCategoryTV.editing = !_productCategoryTV.isEditing; }
@end

最新文章

  1. Ubuntu 12.4 Apache2 安装教程
  2. My安卓知识2--使用listview绑定sqlite中的数据
  3. 剑指offer系列39-----矩阵中的路径
  4. 1.C#基础篇--&gt;封装、继承和多态
  5. 【笨嘴拙舌WINDOWS】BMP图片浏览器
  6. A Bit Fun
  7. 《Android源代码设计模式解析与实战》读书笔记(十四)
  8. POJ 1741 Tree(树的点分治,入门题)
  9. 【Unity3D】Unity3D 让角色的头部望向鼠标
  10. .NET面试常考算法
  11. spring-data-jpa——如果使用了one-to-many,many-to-one的注解,在Jackson进行json字符串化时出现错误的解决方案
  12. gentoo emacs 中文输入法 呼出
  13. CentOS7 下安装mysql历程
  14. CDH的安装和设置
  15. 虚函数_构造函数_测试_VS2010x86
  16. 字符串拼接和dom回流
  17. WebForm——浏览器兼容、旋转、缩放、倾斜、移动
  18. 高版本SQL备份在低版本SQL还原问题
  19. Sublime Text 3 配置Python3.x
  20. springboot整合mybatis增删改查(四):完善增删改查及整合swgger2

热门文章

  1. C# double类型精度丢失问题
  2. CSS 表格基本使用 案例
  3. python all用法记录
  4. python与redis交互(4)
  5. xshell 所选的用户密钥未在远程主机上注册;无法加载密钥
  6. YBT 1633:【例 3】Sumdiv
  7. 《剑指offer》面试题20. 表示数值的字符串
  8. Javascript实现全选按钮
  9. [源码分析] Facebook如何训练超大模型 --- (2)
  10. 【记录一个问题】golang的xorm组件更新数据库未生效