iOS UITableView(五) cell的文字操作及响应事件

//下面介绍下cell上的文字操作

    cell.textLabel.numberOfLines=2;//字数长的话可以换行

    cell.textLabel.font=[UIFontsystemFontOfSize:10];//设置字号

    cell.textLabel.textColor=[UIColorredColor];//设置颜色

    cell.textLabel.textAlignment=NSTextAlignmentLeft;//设置对齐方式

    //cell.textLabel.frame   可以设置label的坐标

    //label所具有的属性cell.textLabel也是有的

//cell的几种accessoryType样式

  cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;

   /*

    UITableViewCellAccessoryNone,                   // don't show any accessory view

    UITableViewCellAccessoryDisclosureIndicator,    // regular chevron. doesn't track

    UITableViewCellAccessoryDetailDisclosureButton, // info button w/ chevron. tracks

    UITableViewCellAccessoryCheckmark,              // checkmark. doesn't track

    UITableViewCellAccessoryDetailButton NS_ENUM_AVAILABLE_IOS(7_0) // info button. tracks

     */

//其中的button有代理

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{

   NSLog(@"123");

}


可以通过

cell.accessoryView的方法自定制button 并且实现方法




-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    //在这里面我们可以设置cell被选中之后的操作,比如页面跳转,或者其它动作

    //取消选中状态

    [tableView deselectRowAtIndexPath:indexPathanimated:YES];




}


//如果我不想指定的cell有触发事件可以这样

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    //我让cell点击的时候没有反应

    return nil;

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值