Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting rows in uitableview

I am Having an application where, if the user enters data the rows will be updated with that data

Can i use One Single Button say 'delete' which when clicked will delete all the rows in the tableview at once.?

like image 907
Chandu Avatar asked Jun 15 '26 14:06

Chandu


2 Answers

Yes you can do that. First remove all data from your data source, then reload your table. For ex. -

[yourArrayDataSource removeAllObjects];
[yourTable reloadData];

To animate the deletion of rows - do this in an IBAction method & link it to your UIButton. As soon as you press the button you will have a smooth awesome animation making all your rows fade out.

-(IBAction)deleteRows
{
    [yourTable beginUpdates];
    for(int i=0; i<[yourArrayDataSource count]; i++)
    {
        indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        [self.searchResTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]  withRowAnimation:UITableViewRowAnimationFade];
    }
    [yourTable endUpdates];
}

There are various animations that you can use here-

UITableViewRowAnimationBottom
UITableViewRowAnimationFade
UITableViewRowAnimationMiddle
UITableViewRowAnimationNone
UITableViewRowAnimationRight
UITableViewRowAnimationTop
like image 179
Srikar Appalaraju Avatar answered Jun 18 '26 04:06

Srikar Appalaraju


make a button and in the button action method

-(IBAction)deleteRows
{
     [array removeAllObjects];
    [tableview reloadData];
}
like image 43
Tendulkar Avatar answered Jun 18 '26 03:06

Tendulkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!