uitableviewcell

使用UITableViewController


//初始化UITAbleviewcontroller 并且分配空间,初始化UItableviewcontroller 的风格

UITableViewController *tableViewController=[[ UITableViewController alloc]initWitchStyle:UITableViewCellStyleDefault];


创建一个导航控制器,并且把导航控制器的rootviewcontroller

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];


讲讲tableview, tableview主要有两个方面,一个是显示(uitableviewdatasource),一个是动作(uitableviewdelegate)

tableview的组成

了解了组成,就知道怎么设置属性,需要设置的地方就知道了

section的数目 ----用到uitableviewdatasource的方法 -(NSInteger)numberofsectionintableview:(uitableview)uitableview

row的数目 ----用到了uitableviewdatasource的方法-(nsinteger)tableview:(uitableview)tableview numberofrowinsection:(nsinteger)section

table header

section header

table cell

section footer



显示cell

-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowindexpath:(nsindexpath)indexpath


然后再这个方法里面创建cell

创建一个cell的一个可以重复使用的模板,dequeuereusablecellwithidentifier:  indexPath    这个方法试用与IOS 6  哪里好呢,不知道 ,呵呵

UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

if(!cell){

cell= [ uitableviewcell alloc]initwithstyle: xxx reuseidentifier:@"MyIdentifier"

}

cell.textlabel.text = xxx

cell.detailtextlabel.text = xxx


设置一下cell的属性 OK



然后呢你想点击一下CELL的时候,切换到下一个页面,  或者点击cell的accessory的时候切换页面,就需要用到uitableviewdalegate的方法了


-(void) tableview:(uitableview *)tableview didselecrowatindexpath:(nsindexpath)indexpath


nsinteger row = indexpath.row                           //获取行号

idobjtodispaly =[myobjects objctatindex:row]  //把行的内容传给下一个view  根据这个内容作出不同的选择


myviewcontroller *myviewcontroller = 初始化;


通过导航,把视图切换过去

[self.navigationcontrollerpushviewcontroller:myviewcontroller animated:YES];



手工,视图切换过去了,那



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值