DataSet装换为泛型集合 222
1.模型CellItem.h
#import <Foundation/Foundation.h> @interface CellItem : NSObject
@property (strong, nonatomic) NSString *title; /** 保存点击cell时要执行的代码*/
@property (strong, nonatomic) void(^block)();
+ (instancetype)itemWithTitle:(NSString *)title;
@end
2.模型CellItem.m
#import "CellItem.h" @implementation CellItem + (instancetype)itemWithTitle:(NSString *)title
{
CellItem *item = [[self alloc] init];
item.title = title;
return item;
} @end
3.TableViewController.m
#import "TableViewController.h"
#import "CellItem.h" @interface TableViewController () @property (strong, nonatomic) NSArray *items; @end @implementation TableViewController - (void)viewDidLoad {
[super viewDidLoad]; CellItem *item1 = [CellItem itemWithTitle:@"撸代码"];
item1.block = ^{
NSLog(@"撸代码");
};
CellItem *item2 = [CellItem itemWithTitle:@"谈恋爱"];
item2.block = ^{
NSLog(@"谈恋爱");
};
CellItem *item3 = [CellItem itemWithTitle:@"挣大钱"];
item3.block = ^{
NSLog(@"挣大钱");
};
self.items = @[item1,item2,item3]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _items.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *ID = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
} // if (indexPath.row==0) {
// cell.textLabel.text = @"撸代码";
// }else if (indexPath.row==1){
// cell.textLabel.text = @"谈恋爱";
// }else if (indexPath.row==1){
// cell.textLabel.text = @"挣大钱";
// } CellItem *item = self.items[indexPath.row];
cell.textLabel.text = item.title; return cell;
} -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // if (indexPath.row==0) {
// cell.textLabel.text = @"撸代码";
// }else if (indexPath.row==1){
// cell.textLabel.text = @"谈恋爱";
// }else if (indexPath.row==1){
// cell.textLabel.text = @"挣大钱";
// } //使用block,免去繁琐的if - esle判断
CellItem *item = self.items[indexPath.row];
if (item.block) {
item.block();
}
} @end
DataSet装换为泛型集合 222的更多相关文章
- C# DataSet装换为泛型集合
1.DataSet装换为泛型集合(注意T实体的属性其字段类型与dataset字段类型一一对应) #region DataSet装换为泛型集合 /// <summary> /// 利用反射和 ...
- 泛型集合与DataSet相互转换
一.泛型转DataSet /// <summary> /// 泛型集合转换DataSet /// </summary> /// <typeparam name=" ...
- DataSet、DataTable转换List(泛型集合与DataSet互相转换 )
using System.Data; using System.Reflection; using System.Collections; using System.Collections.Gener ...
- DataSet和List<T> 泛型之间互相转换 (转载, 作者写的很好)
/DataSet与泛型集合间的互相转换 //利用反射机制将DataTable的字段与自定义类型的公开属性互相赋值. //注意:从DataSet到IList<T>的转换,自定义类型的公开属性 ...
- 泛型学习第三天——C#读取数据库返回泛型集合 把DataSet类型转换为List<T>泛型集合
定义一个类: public class UserInfo { public System.Guid ID { get; set; } public string LoginName ...
- 类库、委托、is as运算符、泛型集合
类库: 说白了,就是让别人调用你写的方法,并且不让别人看到你是怎么实现的. 如果有功能你不会做,需要别人帮忙,那么你的同事可以帮你写好一个类,然后你来调用这个类中的方法,完成你的项目. 1.C#源代码 ...
- C#读取数据库返回泛型集合(DataSetToList)
一般我们用使用ADO.NET查询数据库返回泛型集合使用SqlDataReader逐行读取数据存入对象 代码 }
- 泛型集合、datatable常用数据类型转换Json帮助类
泛型集合.datatable常用数据类型转换Json帮助类 using System; using System.Data; using System.Configuration; using Sys ...
- [c#基础]泛型集合的自定义类型排序
引用 最近总有种感觉,自己复习的进度总被项目中的问题给耽搁了,项目中遇到的问题,不总结又不行,只能将复习基础方面的东西放后再放后.一直没研究过太深奥的东西,过去一年一直在基础上打转,写代码,反编译,不 ...
随机推荐
- C#检验参数合法性公用方法
#region 检验参数合法性,数值类型不小于0,引用类型不能为null,否则抛出异常 /// <summary> /// 检验参数合法性,数值类型不小于0,引用类型不能为null,否则抛 ...
- iOS PhotoKit框架如何获取视频文件大小
// 获取相册中的资源[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUI ...
- Chrome 开发工具之Console
前段时间看git的相关,记的笔记也大致写到了博客上,还有些因为运用不熟,或者还有一些疑惑点,暂时也不做过多纠缠,之后在实践中多运用得出结论再整理分享吧. 工欲善其事,必先利其器.要想做好前端的工作,也 ...
- 【Phylab2.0】Beta版本项目展示
团队成员 冯炜韬(PM)http://www.cnblogs.com/toka 岳桐宇(后端)http://www.cnblogs.com/mycraftmw 杨子琛(测试&LaTeX)htt ...
- 以最简单方式学习Linux
有很多关于Linux的书籍,博客.大多数都会比较"粗暴"的将一大堆的命令塞给读者,从而使很多.NET程序员望而却步.未入其门就路过了. 所以我设想用一种更为平滑的学习方式, 就是在 ...
- Python学习笔记(1)
001 #通过bat命令运行pyhon py文件,并将结果输出到txt文件.# D:\ResearchContent\Exercise_Programm\Start\Start.py>C:\Us ...
- set和enum类型的用法和区别
mysql中的set和enum类型的用法和区别 mysql中的enum和set其实都是string类型的而且只能在指定的集合里取值, 不同的是set可以取多个值,enum只能取一个值. 1 2 3 ...
- Linux如何进行文件管理
Linux中的所有数据都被保存在文件中,所有的文件被分配到不同的目录.目录是一种类似于树的结构,称为文件系统.当你使用Linux时,大部分时间都会和文件打交道,通过本节可以了解基本的文件操作,如创建文 ...
- 5. web前端开发分享-css,js深化篇
一. css练习网易专题: 1. http://news.163.com/ 新闻 跟腾讯的新闻版式大体没有大的变化,只是细节. 2. http://news.163.com/photo/#Curren ...
- TeamViewer 12.0.71503 Patch By.Sound
TeamViewer - the All-In-One Software for Remote Support and Online Meetings - Remote control any com ...