IOS基础-UITableViewController

本文深入探讨了UIKit中的表视图组件,包括UITableViewController、UITableView及UITableViewCell的使用方法与自定义技巧。介绍了不同样式与风格的应用场景,并提供了两种自定义UITableViewCell的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.youkuaiyun.com/swingpyzf/article/details/10012779


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值