How To Add Delete Data From TableView In iPhone

In this application we will see how to add delete data from the tableview. Let see how it will worked.

Step 1: Create a new application using View base template. Give the application name “AddDelete”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: xpand classes and notice Interface Builder created the AddDeleteViewController class for you. Expand Resources and notice the template generated a separate nib, AddDeleteViewController.xib, for the “AddDelete”.

Step 4: In the AddDeleteAppDelegate.m file make the following changes:

 

 

 

Step 5: Open the AddDeleteViewController.h file, in this file we have added two protocols that are needed for it to act as the delegate and datasource for the table view,declare UITableView for displaying the list of data and NSMutableArray for insertion and deletion operations to the basic array handling and added one IBAction: method.

 

 

 

Step 6: Double click your AddDeleteViewController.xib file and open it to the Interface Builder. First drag the tableview from the library and place it to the view window, select the tableview from the view window and bring up connection Inspector, then you’ll notice that the first two available connections fare dataSource and delegate. Drag from the circle next to each of those connections over the File’s Owner icon. Now select the File’s Owner icon from the main window and bring up Connection Inspector and drag from the tableView to TableView. You have done all the connection, so save the .xib file, close it and go back to the Xcode.

Step 7: In the AddDeleteViewController.m file make the following changes :

 

 

 

Step 8: Now compile and run the application in the Simulator.

You can Downloaded SourceCode from here AddDelete 2

Leave a Comment:

4 comments
ADog says June 22, 2010

Downloaded source code. Tried it out Add Data adds SturDay… no complaints there, but when I tried moving several rows to different places, the program terminated due to an uncaught exception. This code is not very reliable. Please fix. Thanks for the tutorial attempt by the way.

Reply
AD says July 15, 2010

Crashes when you try to move the “Add entry” button

Reply
caspa says August 3, 2011

this disables the option to move the add entry button
– (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row != [dataList count])
return YES;
else
return NO;
}

Reply
Jose says May 11, 2012

– Not up to date
– Code comes with a few errors
– Source code download is for Mac OSX 64 bit

Reply
Add Your Reply