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#基础]泛型集合的自定义类型排序
引用 最近总有种感觉,自己复习的进度总被项目中的问题给耽搁了,项目中遇到的问题,不总结又不行,只能将复习基础方面的东西放后再放后.一直没研究过太深奥的东西,过去一年一直在基础上打转,写代码,反编译,不 ...
随机推荐
- wpf 异常处理和关闭进程
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- OOP,WEB开发实用小技巧
偶然读到一篇博客,记录一下心得.这种设计对于新手来说一般是想不到的,它充分的发挥了OOP语言的特性,让代码专用而清爽.这是不是重构的思想呢? 我们在写业务层的时候,有很多方法是重复功能的,我们就可以使 ...
- App Extension访问Cocoapods引入的第三方库
步骤一: PROJECT --info --configurations,将对应的Debug和Release 设置成pods.debug和pods.release 步骤2:编译一下(本人遇到的问 ...
- SSH正反向隧道
正向隧道 拓扑如下: 说明: CLIENT不能直接访问WEB服务器,AGENT可访问WEB服务器: 在AGENT上通过创建ssh正向隧道,使CLIENT可以通过AGENT间接访问WEB服务器: AGE ...
- SQL Server群集如何在线检测
SQL Server群集知识介绍 Windows群集安装 基于iSCSI的SQL Server 2012群集测试 前言 群集的检测是调用dll资源,例如对于共享存储,ip,网络名称与DTC 这类Win ...
- 在sql语句中使用 xml for path 格式化字符串的方法总结
此方法实现的是将查询表中的某个字段,格式化成 字符串1,字符串2,字符串3...的格式 假设我们现在有两个表 分别是 分组表 grouped和分组成员表 groupuser grouped表有连个字 ...
- 第4月第1天 makefile automake
1. gnu make的函数调用是$,比如 $(subst ee,EE,feet on the street) 规则中“TARGETS”可以是空格分开的多个文件名 a all: echo $(subs ...
- php 路径的理解
当php文件用require方式包含了另外一个文件,这另外文件引用的图片是相对目录下的内容时,而该相对目录是指包含目录的文件的 -----index.php -----default 目录 --- ...
- PHP 站点相对包含,路径的问题解决方法(include,require)
以前看了,很多框架,基本上很少使用相对路径包含.而一般很多做php web站点,喜欢用相对路径. 认为这样,无论目录放到那里. 只要跟另外目录关系一致.那么就不会出现问题.如果一个站点,一般都认为,如 ...
- Asp.Net Core--发布到IIS
翻译如下: 支持的操作系统 Windows 7及更高版本 Windows Server 2008 R2及更高版本 概念上,本文档中描述的IIS配置也适用于在Nano Server IIS上托管ASP. ...