Is it possible to programmatically show the red delete button on a UITableViewCell?

后端 未结 4 1966
傲寒
傲寒 2020-12-29 21:41

There are lots of similar questions on here, but none that I think specifically ask this question, which is, is there any way in code to force the red delete button to appea

4条回答
  •  情深已故
    2020-12-29 22:26

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *CellIdentifier = [NSString stringWithFormat:@"cell %d",indexPath.row];
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            if(TableMethod==1)
            {
                UIButton *delete_btn=[UIButton buttonWithType:UIButtonTypeCustom];
                [delete_btn setFrame:CGRectMake(10,15,25,25)];
                delete_btn.tag=indexPath.row;
                [delete_btn setImage:[UIImage imageNamed:@"remove_Icone.png"] forState:UIControlStateNormal];
                [delete_btn addTarget:self action:@selector(delete_btn:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:delete_btn];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
    
        // Configure the cell.
        return cell;
    }
    
    
    - (IBAction)delete_btn:(id)sender
    {
        UIButton *buttontag = (UIButton *)sender;
        //NSLog(@"%d",buttontag.tag);
        Delete_row = buttontag.tag;
    
        UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Delete Reservation"   message:@"Are you sure to want Delete Reservation ??" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel",nil];
        Alert.tag=1;
        [Alert show];
        [Alert release];
    }
    
    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
    {
        if(alertView.tag==1)
        {
            if(buttonIndex == 0)
            {
                // delete row
            }
        }
    }
    

提交回复
热议问题