【UIKit】UITableView.03

UITableView.03:

【1】拖入一个UITableView

【2】将TableView的dataSource与控制器连接

【3】首先得遵循UITableView的数据源协议<UITableViewDataSource>

【4】加入图标文件

【5】代码

1.设置一共多少组,系统默认是1组,所以不写的话就默认1组

#pragma mark 返回多少组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // 在这里默认是1,写与不写一样
    return 1;
}

2.返回多少行,这里返回9行

#pragma mark 返回一组多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 9;
}

3.返回每一行的具体数据

  下表为箭头样式

UITableViewCellAccessoryCheckmark
  
UITableViewCellAccessoryDetailButton
UITableViewCellAccessoryDetailDisclosureButton
  
UITableViewCellAccessoryDisclosureIndicator
  
UITableViewCellAccessoryNone
表示没有

#pragma mark 返回具体数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle
                                            reuseIdentifier:nil];
  /************************设置左边图标*******************/
    // 1.取出第i行所使用的图片名称
    NSString *imageName=[NSString stringWithFormat:@"00%d.png",indexPath.row+1];
   // 2.cell.imageView.image=上面取得的image的名字
    cell.imageView.image=[UIImage imageNamed:imageName];

    /***********************设置主标题*********************/
    [email protected]"12312432";
    // 设置子标题,需要在上面的UITableViewCellStyleDefault改为UITableViewCellStyleSubtitle
    [email protected]"详细描述"; //子标题内容为详细描述

    // 设置cell箭头样式
    cell.accessoryType=UITableViewCellAccessoryCheckmark;

    return cell;
}

4.设置每一行的行高

  1)加入代理

2) 添加代理协议<UITableViewDelegate>

3) 调整高度

#pragma mark- 调整每一行的高度,代理方法
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 设置所有高度为70;
        return 60;

    // 也可以根据传入的不同内容进行不同的高度设置
    // 行数越多,高度越高
    //return 40+indexPath.row*5;
}

【UIKit】UITableView.03,布布扣,bubuko.com

时间: 2024-08-14 02:28:13

【UIKit】UITableView.03的相关文章

【UIKit】UITableView.04

UITableView.04: [1]拖入一个UITableView [2]将TableView的dataSource与控制器连接 [3]首先得遵循UITableView的数据源协议<UITableViewDataSource> [4]加入图标文件 [5]代码 1.创建一个Product类,用来作为对象内容表示产品信息 2.在Product.h中添加声明代码 @interface Product : NSObject /*********设置产品内容信息*********/ /* 图片*/ @

【UIKit】UITableView.05 性能优化

UITableView.05 性能优化: [为何要性能优化]:TableView拖屏过程中,不断有对象"消失"在屏幕上,但是这样的对象还是存在的,当拖拉过多后,导致内存严重泄漏. 解决方法:仅提供有限的对象,拖拉过程中,只是将内存地址存放的内容进行改变. [旧代码] -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITable

【UIKit】UITableView.02

UITableView.02: [1]拖入一个UITableView [2]将TableView的dataSource与控制器连接 [3]首先得遵循UITableView的数据源协议<UITableViewDataSource> [4]将数据plist文件拖入 [5]代码 1.viewDidLoad只加载一次,所以用来加载plist文件中的数据. 新建一个bundel用来指定文件路径 pathForResource:文件名 ofType:文件格式 - (void)viewDidLoad { [

【UIKit】UITableView.09 自定义cell

UITableView.09 自定义cell : 注意:在创建一个故事版的时候,需要将控制器的class修改成对应的class否则效果实现不了[如图] 1.这段代码就是用来设置cell所对应的xib,类似于绑定  // 1.想要使用文件包里面的资源就要使用[NSBundle mainBundle] // 2.loadNibNamed的意思是加载一个xib文件,名字为BookCell cell=[[[NSBundle mainBundle]loadNibNamed:@"BookCell"

【UIKit】UITableView.06

UITableView.06: [1]拖入ToolBar,TableView [2]连线,设置代理模式,数据源等(ToolBar中的垃圾桶也需要连接方法removeRow) [3]代码 1.声明 mydata :所有的数据,人工初始化的数据30行. selectedData:选中的数据,视频中点击后选中的数据 selectedRows:只是为了删除时候能得到所选择的数据行而创建的数组 @interface ViewController () // 所有的总数据 @property (strong

【UIKit】UITableView.07 编辑模式

[1]拖动好界面 [2]设置协议,数据源 [3]代码 1.声明可变数组,用来存放所有数据对象 @interface ViewController () @property(nonatomic,strong)NSMutableArray *mydata; @end 2.初始化数据[创建30个对象数据] - (void)viewDidLoad { [super viewDidLoad]; self.mydata=[NSMutableArray array]; for(int i =0;i<30;i+

【UIKit】UITableView.01

UITableView.01: section:组别 row:行号 [1]拖入一个UITableView [2]将TableView的dataSource与控制器连接 [3]首先得遵循UITableView的数据源协议<UITableViewDataSource> 代码 1.加入显示数据内容 - (void)viewDidLoad { [super viewDidLoad]; [email protected][@"广州" ,@"梅州",@"深

【UIKit】UITableView.08 常用属性

UITableView.08 常用属性:  以上图片转自http://blog.csdn.net/totogo2010/article/details/7642908 以上图片转自http://blog.csdn.net/totogo2010/article/details/7642908 1.设置Section的数量 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return TitleData; }

【UIKit】控制器之间的切换2 【Push】

[控制器切换Push][?Code] 1.创建3个xib和控制器 2.在AppDelegate中设置首先启动的页面 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds] ]; self.