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. 【USACO 3.2】Sweet Butter(最短路)

    题意 一个联通图里给定若干个点,求他们到某点距离之和的最小值. 题解 枚举到的某点,然后优先队列优化的dijkstra求最短路,把给定的点到其的最短路加起来,更新最小值.复杂度是\(O(NElogE) ...

  2. 【BZOJ-2555】SubString 后缀自动机 + LinkCutTree

    2555: SubString Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 1936  Solved: 551[Submit][Status][Di ...

  3. 【BZOJ-3881】Divljak AC自动机fail树 + 树链剖分+ 树状数组 + DFS序

    3881: [Coci2015]Divljak Time Limit: 20 Sec  Memory Limit: 768 MBSubmit: 508  Solved: 158[Submit][Sta ...

  4. 8 HTML&JS等前端知识系列之jquery的自定义方法

    preface 有时候我们在前端写jquery的时候,会自己自定义些方法,这样可以不需要重复造轮子.先说说2种自定义方法的区别: 不跟在选择器后面的 跟在选择器后面的. 那下面说说如何自定义jquer ...

  5. Delphi 获取时间的年月日

    procedure TFrmLltj.FormActivate(Sender: TObject); var   Present: TDateTime;   Year, Month, Day, Hour ...

  6. thinkphp3.2.3中U()方法和redirect()方法区别

    今天博主看3.1的教程,学着3.2,就遇到了这个坑,怎么就是不跳转呢,很纳闷!! 在thinkphp3.1 中 U()方法是可以执行跳转的(看视频教程里面是可以的,博主没有测试过). 但是在think ...

  7. Java虚拟机(JVM)以及跨平台原理详细的介绍

    相信大家已经了解到Java具有跨平台的特性,可以"一次编译,到处运行",在Windows下编写的程序,无需任何修改就可以在Linux下运行,这是C和C++很难做到的.那么,跨平台是 ...

  8. Angularjs兼容IE

    http://www.tuicool.com/articles/EJv6riY http://www.angularjs.cn/A00v http://www.cnblogs.com/ahl5esof ...

  9. Java学习笔记(未完待续)

    变量的作用域(scope)是指变量可以在程序中引用的范围.在方法中定义的变量称为局部变量(local variable).局部变量的作用域从声明变量的地方开始,直到包含该变量的块结束为止.局部变量都必 ...

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

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