uitableview学习

来源:互联网 发布:申通快递单打印软件 编辑:程序博客网 时间:2024/04/24 12:59

设置圆角

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view from its nib.    self.mytv.layer.cornerRadius = 8.0;}



响应单元格右侧按钮

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString* cellID = @"cell";        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];    if(nil == cell)    {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];    }    cell.selected = NO;    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;    cell.textLabel.text = @"f";    cell.detailTextLabel.text = @"ff";    cell.imageView.image = [UIImage imageNamed:@"avatar.png"];    return cell;}

添加脚注

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;


弹出增加,删除按钮

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"edit" style:UIBarButtonItemStylePlain target:self action:@selector(edit)];}- (void)edit{    _edit = !_edit;    [super setEditing:_edit animated:YES];    [_mytv setEditing:_edit animated:YES];}



点击可以蹦出删除,添加按钮

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{    if(indexPath.row %2 == 1)    {        return UITableViewCellEditingStyleInsert;    }    else    {        return UITableViewCellEditingStyleDelete;    }}



0 0