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的更多相关文章

  1. C# DataSet装换为泛型集合

    1.DataSet装换为泛型集合(注意T实体的属性其字段类型与dataset字段类型一一对应) #region DataSet装换为泛型集合 /// <summary> /// 利用反射和 ...

  2. 泛型集合与DataSet相互转换

    一.泛型转DataSet /// <summary> /// 泛型集合转换DataSet /// </summary> /// <typeparam name=" ...

  3. DataSet、DataTable转换List(泛型集合与DataSet互相转换 )

    using System.Data; using System.Reflection; using System.Collections; using System.Collections.Gener ...

  4. DataSet和List<T> 泛型之间互相转换 (转载, 作者写的很好)

    /DataSet与泛型集合间的互相转换 //利用反射机制将DataTable的字段与自定义类型的公开属性互相赋值. //注意:从DataSet到IList<T>的转换,自定义类型的公开属性 ...

  5. 泛型学习第三天——C#读取数据库返回泛型集合 把DataSet类型转换为List<T>泛型集合

    定义一个类: public class UserInfo    {        public System.Guid ID { get; set; } public string LoginName ...

  6. 类库、委托、is as运算符、泛型集合

    类库: 说白了,就是让别人调用你写的方法,并且不让别人看到你是怎么实现的. 如果有功能你不会做,需要别人帮忙,那么你的同事可以帮你写好一个类,然后你来调用这个类中的方法,完成你的项目. 1.C#源代码 ...

  7. C#读取数据库返回泛型集合(DataSetToList)

    一般我们用使用ADO.NET查询数据库返回泛型集合使用SqlDataReader逐行读取数据存入对象 代码 }

  8. 泛型集合、datatable常用数据类型转换Json帮助类

    泛型集合.datatable常用数据类型转换Json帮助类 using System; using System.Data; using System.Configuration; using Sys ...

  9. [c#基础]泛型集合的自定义类型排序

    引用 最近总有种感觉,自己复习的进度总被项目中的问题给耽搁了,项目中遇到的问题,不总结又不行,只能将复习基础方面的东西放后再放后.一直没研究过太深奥的东西,过去一年一直在基础上打转,写代码,反编译,不 ...

随机推荐

  1. EF 二级缓存 EFSecondLevelCache

    EFSecondLevelCache ======= Entity Framework .x Second Level Caching Library. 二级缓存是一个查询缓存.EF命令的结果将存储在 ...

  2. Android——Handler

    Handler——是Android给我们提供用来更新UI的一套机制,也是一套消息处理机制,可以发送也可以处理消息 主要作用:1)在新启动的线程中发送消息:2)在主线程中获取.处理消息. (想想银行取钱 ...

  3. win7下安装mysql后修改密码

    mysql的安装教程网上很多,此处不过多介绍,个人觉得下面这篇教程是比较好的,一步到位.MySQL 5.7.9 ZIP 免安装版本配置过程_百度经验  http://jingyan.baidu.com ...

  4. 练习JavaScript实现梯形乘法表

    效果: 表格用html中的table,tr,td,然后利用for语句实现,循环输出行和列,再根据行列的数量进行乘法运算,第一个for循环输出9行,然后内嵌一个for,在条件表达式中取第一个for循环的 ...

  5. chorme浏览器调试Android设备

    Android设备开启开发者模式,并打开USB调试: 接着在Android设备上运行项目 在chrome浏览器打开F12: 在Remote devices里即可调试页面. ! 一般需要FQ

  6. UVA1368

    用一个二维数组装m个字符串,然后用一个数组装每个字符串的hamming距离.找到最小的hanming距离即可 #include<stdio.h> #include<string.h& ...

  7. 字符串 中的split 与数组中的join

    关于基础,总是隔一段时间,就得看一次,要不不用总是忘,今天又重新看了,一下字符串对象的split,然后就想到了数组对象的join. var str='wo shi yi ge js'; var str ...

  8. 一个简单的 Web 服务器 [未完成]

    最近学习C++,linux和网络编程,想做个小(mini)项目.  就去搜索引擎, 开源中国, Sourceforge上找http server的项目. 好吧,也去了知乎.    知乎上程序员氛围好, ...

  9. 记一次WinForm程序中主进程打开子进程并传递参数的操作过程(进程间传递参数)

    目标:想在WinForm程序之间传递参数.以便子进程作出相应的处理. 一种错误的方法 父进程的主程序: ProcessStartInfo psi = new ProcessStartInfo(); p ...

  10. Web API系列(三)统一异常处理

    前面讲了webapi的安全验证和参数安全,不清楚的朋友,可以看看前面的文章,<Web API系列(二)接口安全和参数校验>,本文主要介绍Web API异常结果的处理.作为内部或者是对外提供 ...