IOS, Objective-c

How to Edit UITableViewCell in IOS

In Most of cases we use UITableView for displaying texts or contents. Specially we use UiTableView for present our contents . But while the time of editing the contents of UITableView Cell we use different UiView or Different Viewcontroller.In This Article we are trying to figure it out how to use canEditRowAtIndexPath or commitEditingStyle method for editing Table Cell.
Edit Mode on a UITableView is configured through the

and

methods of the UITableView DataSource Protocol.

Enabling Edit Mode

Return YES for all IndexPath Sections / Rows you want Edit Mode enabled for.

The code above will disable Edit Mode for Row 1 of the first Section, but will enable it for all other Sections/Rows.

Configuring Edit Mode – UI Controls:

There is no direct way to hook up a UIButton to a tableView, to enter into Edit Mode. Instead, set up an IBAction from the required UIButton, that does the following:

You do not need to do this though, if the user can only delete rows. Swipe-to-delete will be enabled by default if a tableView can be edited.

Configuring Edit Mode – The TableView:

The following code will affect how new Rows are added, and existing ones deleted.

Enabling Cell Selection during Edit Mode:

You need to change a setting in Interface Builder if you want to enable selections when editing (why this is not the default is anybody’s guess). Select the tableView in IB, and change the setting under ‘Editing’, to allow ‘Single Selection during Editing”.

Edit mode selection

Finally, if you need different behavior in your app when selecting cells during edit mode, you also need to change the didSelectRowAtIndexPath method, to handle this.

mycodetips

Passionate about coding and software development holding 10+ Years of experience including 6+ years of experience on Mobile application Development.

More Posts