IOS基础-UITableViewController
2015-12-15 21:25
615 查看
UITableViewController 为实现了基于表格提供了方便,先继承UITableViewController 再在界面上拖入UITableViewController对象
UITableViewController本身实现了UITableViewDelegate,UITableViewDataSource
NS_CLASS_AVAILABLE_IOS(2_0)@interface UITableViewController
:UIViewController <UITableViewDelegate,UITableViewDataSource>
UITableViewController->UITableView->UITableViewCell
UITableViewCell的stype
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
//图像+文本 对应界面上BASIC
UITableViewCellStyleDefault,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x)
//文本+详细 无图像 对应LEFT DETAIL
UITableViewCellStyleValue1,// Left aligned label on left and right aligned label on right with blue text (Used in Settings)
//图像+文本+详细 对应 RIGHT DETAIL
UITableViewCellStyleValue2,// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)
//图像+文本+详细(正文下方) SUBTITLE
UITableViewCellStyleSubtitle// Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).
};
UITableView的stype
typedef NS_ENUM(NSInteger, UITableViewStyle) {
//普通 只有行 没有分组
UITableViewStylePlain, // regular table view
//可以分组 每组可以定义组名
UITableViewStyleGrouped // preferences style table view
};
=========自定义UITableViewCell的两种方法
两种方法都的首先继承UITableViewCell 如MyUITableViewCell 创建之类
1.创建之类时选择 同时创建 xib 那之后就在xib上拖入TableViewCell控件 再拖入其它控件
如LABLE IMAGE VIEE 因xib 的class创建时自动关联了MyUITableViewCell
后续跟 MasterViewController中得
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathMyUITableViewCell
MyTableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"Cell"forIndexPath:indexPath];
cell.mText.text =@"hxy";//mText 变量需在MyUITableViewCell定义
cell.mDetail.text =@"hexiaoyu";
cell.mImage.image =[UIImageimageNamed:@"28.jpg"];
2.创建子类时不选择xib创建,那xib单独创建 基于empty创建xib
后续一样在xib上拖入TableViewCell控件 再拖入其它控件
如LABLE IMAGE VIEE,并再xib得class关联 类 MyUITableViewCell
填写xib 控件的Identifier 方便复用cell。
//自定义cell类
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
if (cell == nil) {
//通过xib的名称加载自定义的cell
cell = [[[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil] lastObject];
}
cell.textLabel.text = [object description];
cell.detailTextLabel.text = @"detail";
cell.imageView.image = [UIImage imageNamed:@"28.jpg"];
========网上参考===
http://blog.csdn.net/swingpyzf/article/details/10012779
UITableViewController本身实现了UITableViewDelegate,UITableViewDataSource
NS_CLASS_AVAILABLE_IOS(2_0)@interface UITableViewController
:UIViewController <UITableViewDelegate,UITableViewDataSource>
UITableViewController->UITableView->UITableViewCell
UITableViewCell的stype
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
//图像+文本 对应界面上BASIC
UITableViewCellStyleDefault,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x)
//文本+详细 无图像 对应LEFT DETAIL
UITableViewCellStyleValue1,// Left aligned label on left and right aligned label on right with blue text (Used in Settings)
//图像+文本+详细 对应 RIGHT DETAIL
UITableViewCellStyleValue2,// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)
//图像+文本+详细(正文下方) SUBTITLE
UITableViewCellStyleSubtitle// Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).
};
UITableView的stype
typedef NS_ENUM(NSInteger, UITableViewStyle) {
//普通 只有行 没有分组
UITableViewStylePlain, // regular table view
//可以分组 每组可以定义组名
UITableViewStyleGrouped // preferences style table view
};
=========自定义UITableViewCell的两种方法
两种方法都的首先继承UITableViewCell 如MyUITableViewCell 创建之类
1.创建之类时选择 同时创建 xib 那之后就在xib上拖入TableViewCell控件 再拖入其它控件
如LABLE IMAGE VIEE 因xib 的class创建时自动关联了MyUITableViewCell
后续跟 MasterViewController中得
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathMyUITableViewCell
MyTableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"Cell"forIndexPath:indexPath];
cell.mText.text =@"hxy";//mText 变量需在MyUITableViewCell定义
cell.mDetail.text =@"hexiaoyu";
cell.mImage.image =[UIImageimageNamed:@"28.jpg"];
2.创建子类时不选择xib创建,那xib单独创建 基于empty创建xib
后续一样在xib上拖入TableViewCell控件 再拖入其它控件
如LABLE IMAGE VIEE,并再xib得class关联 类 MyUITableViewCell
填写xib 控件的Identifier 方便复用cell。
//自定义cell类
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
if (cell == nil) {
//通过xib的名称加载自定义的cell
cell = [[[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil] lastObject];
}
cell.textLabel.text = [object description];
cell.detailTextLabel.text = @"detail";
cell.imageView.image = [UIImage imageNamed:@"28.jpg"];
========网上参考===
http://blog.csdn.net/swingpyzf/article/details/10012779
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- winform异型不规则界面设计的实现方法
- Android中设置只有程序第一次运行才显示的界面实现思路
- hta 实现的五子棋界面
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- android开发之欢迎界面的小例子
- C#中载入界面的常用方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- android编程实现局部界面动态切换的方法