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#基础]泛型集合的自定义类型排序
引用 最近总有种感觉,自己复习的进度总被项目中的问题给耽搁了,项目中遇到的问题,不总结又不行,只能将复习基础方面的东西放后再放后.一直没研究过太深奥的东西,过去一年一直在基础上打转,写代码,反编译,不 ...
随机推荐
- 【USACO 3.2】Magic Squares
题意 4*2个格子分别为 1234 8765 的魔板有3种操作,A:上下两排互换,B:最后一列放到第一列前面,C:中间四个顺时针旋转1格. 现在给出目标状态,找出最少步数可从原始状态到达目标状态,且输 ...
- java 方法
方法命名规范要求 类的命名规范:“全部单词的 首字母必须大写”.那么在定义方法的时候也是有命名规范要求的:“第 一个单词的首字母小写,之后每个单词的首字母大写”,那么这就是方法 的命名规范. 递归调用 ...
- Généralement c'est un mélange qui me devient personnellement
Parmi mes plus grands problèmes personnels avec maisons de rue conventionnelles est en fait ils sont ...
- vim + ctags + taglist配置和使用
vim +ctags + taglist ,ctags+cscope 安装配置和使用 内容:VIM下ctags和taglist的安装配置方法:一键安装 ctags和cscope的方法 :vim语法高亮 ...
- AngularJS 依赖注入
依赖注入(Dependency Injection,简称DI)是一种软件设计模式,在这种模式下,一个或更多的依赖(或服务)被注入(或者通过引用传递)到一个独立的对象(或客户端)中,然后成为了该 ...
- TeamViewer 12.0.71503 Patch By.Sound
TeamViewer - the All-In-One Software for Remote Support and Online Meetings - Remote control any com ...
- nyoj 473 A^B Problem
A^B Problem 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Give you two numbers a and b,how to know the a^ ...
- EBS 11i 的工作流列表
总帐模块(GL) GIS(Global Intercompany System)通知 GL自动分配 GL成批分配流程 GL分配流程 GL过帐流程 GL经常性日记帐流程 PA分配组流程 日记帐审批 应付 ...
- LPC1769 CAN的自测试模式
一.背景 客户要了一块单路CAN的板子,他希望在没有其他板子的情况下进行自行测试,然后按照我写的 APP选择自收发测试选项,却无法接收到发送的信息,但是外接了一块板子就可以接收到自己发送的 信息:由于 ...
- Linux或Unix环境利用符号链接升级Maven
1,解压Maven到安装目录,在解压目录同一级创建刚解压目录的符号链接,命令如下: ln -s apache-maven-3.3.9 apache-maven 2,配置环境变量,这里Maven主目录环 ...