• UITableView


    //解决scrollView上面的 tableView 滑动冲突 设置一下连个属性 来个控件的滑动事件就不会冲突了

    [scr setDelaysContentTouches:NO];

       [scr setCanCancelContentTouches:NO];

    //根据indexPath 来获取cell

    UITableViewCell*cell=[tableView cellForRowAtIndexPath:indexPath];

    //根据点击的cell 获取indexPath

    NSIndexPath*indexPath=[self.tableView indexPathForSelectedRow];

    //确定cell上的按钮在哪行

    - (void)button:(id)sender {

        UITableViewCell * cell = (UITableViewCell *)[[sender superview] superview];

        NSIndexPath * path = [self.tableView indexPathForCell:cell];

        NSLog(@"index row%d", [path row]);

    }

    //关闭弹簧效果

    _accTableView.bounces = NO;

    //设置交替色

    cell.backgroundColor = (indexPath.row%2)?[UIColor lightGrayColor]:[UIColor grayColor];

    设置cell点击没有选中效果

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    置是否可以滑动属

    tab.scrollEnabled = NO;

    容和边的间距

    m_tableView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0);

        m_tableView.scrollIndicatorInsets = UIEdgeInsetsMake(44, 0, 0, 0);

    置分割线

    UIBlurEffect *blurEffect =[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

    UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];

    _listView.separatorEffect = blurEffect;

     

    Tableview右面的箭头可以自己放一个UIView或者它的子类

    if (indexPath.section == 0) {

    self.swith = [[UISwitch alloc]initWithFrame:CGRectMake(260, 10, 0, 0)];}

    下面的这句话就是把一个选择器放在了箭头的位置

    cell.accessoryView = self.swith;

     

    也可以自定义箭头

    UIImageView *arrow = [[UIImageView alloc]initWithFrame:CGRectMake(285, 20, 8, 14)];

            arrow.image = [UIImage imageNamed:@"5_进入"];

            cell.accessoryView = arrow;

    实现Cell的滑动删除

    需要实现UITableView的代理UITableViewDelegate中如下方法:

     

    先要设Cell可编辑

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

    {

    return YES;

    }

     

    定义编辑样式改变左侧的按钮的样式 删除是'-' 增加是'+'

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

    {

    [tableView setEditing:YES animated:YES];

    return UITableViewCellEditingStyleDelete;

    }

     

    进入编辑模式,按下出现的编辑按钮后

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

    {

    [tableView setEditing:NO animated:YES];

    }

     

             以下方法可以不是必须要实现,添加如下方法可实现特定效果:

     

    修改编辑按钮文字

    - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

    {

    return @"删除";

    }

     

             实现Cell可上下移动,调换位置,需要实现UiTableViewDelegate中如下方法:

     

    先设置Cell可移动

    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

    {

    return YES;

    }

     

    当两个Cell对换位置后

    - (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath

    {

     

    }

     

    设置进入编辑状态时,Cell不会缩进

    - (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath

    {

    return NO;

    }

     

    在下面方法中添加 cell.showsReorderControl =YES;     

    使Cell显示移动按钮      

    - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;

     

     

     

  • 相关阅读:
    1003 Emergency (25分)
    1013 Battle Over Cities (25分)
    1009 Product of Polynomials (25分)
    一元多项式的乘积与和(C++)
    1015 Reversible Primes (20分)
    list()函数对原来类型已经是列表的不会在添加[]
    全局变量把值固定
    python中None与Null的区别
    基础算法之排序
    列表和字符串的方法返回一个新的对象;直接加入到原对象中
  • 原文地址:https://www.cnblogs.com/zhaozhongpeng/p/4867917.html
Copyright © 2020-2023  润新知