您的位置:首页 > 产品设计 > UI/UE

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS 界面 移动开发