UITableView 添加,删除,编辑

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *strone=@"111111111111111";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:strone];
    if (cell==nil) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strone]autorelease];
        
        UISwitch* mySwitch = [[ UISwitch alloc]initWithFrame:CGRectMake(230, 10, 20, 30)];   
       // [mySwitch setBackgroundImage:[UIImage imageNamed:@"bgBlueButton.png"] forState:UIControlStateNormal];    
        [ mySwitch setOn:NO animated:YES];  
        [mySwitch setTag:indexPath.row];
        [mySwitch addTarget:self action:@selector(del:) forControlEvents:UIControlEventValueChanged];    
        [cell addSubview:mySwitch];           
    }
    cell.textLabel.text=[clocknum objectAtIndex:indexPath.row];
   // [cell.lable setText:[arr objectAtIndex:indexPath.section]];
   // [cell imagepeople].image=[UIImage imageNamed:[NSString stringWithFormat:@"%@%d",PEOPLETRING,indexPath.section]];
    

    return cell;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    return [数组 count];
     
}

//添加

//初始时,数组为空,在数组有变化时

 [tableclock reloadData];


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //点击后反显颜色即刻消失
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
 
    [tableView setEditing:YES];


}

//编辑状态
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {  
        NSUInteger row = [indexPath row];

       //从数据源中移除数据

        [clocknum removeObjectAtIndex:row];  
        NSLog(@"===%d",[clocknum count]);
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]  
                         withRowAnimation:UITableViewRowAnimationAutomatic];
        
        [tableclock reloadData];
        [tableView setEditing:NO];

            }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值