Implement A Custom Accessory View For UITableView In iPhone

Implement A Custom Accessory View For UITableView In iPhone

In this application we’ll see how to implement a custom accessory view for your UITableView in the form of a checkmark button.

Step 1: Create a Window base application using template. Give the name of the application “CheckMark”.

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: We need to add the resource file called as “checked.png” and “unchecked.png” into the resource folder. Select resources and add files existing sources and select the checked.png and unchecked.png.

Step 4: Now we’ll add Table view controller class to the project. Choose New file -> Select cocoa touch classes group and then select UITableViewController subclass. Give the name TableView.

Step 5: In the AppDelegate.h file, we define UINavigationController. Make the following changes in the AppDelegate.h file .




Step 6: In the AppDelegate.m file , make the following changes :




Step 7: We added dataArray in the TableView.h file, so make the following changes:




Step 8: Double click the MainWindow.xib file and open it to the Interface Builder. Drag Navigation Controller from the library and place it in the MainWindow. Double click Navigation Controller icon and open the Navigation Controller window. Change the title into “Add CheckMark”. Select View Controller and bring up identity inspector change the class name into TableView. Now drag table view from the library and place it to the Navigation Controller window. Select it and bring up connection inspector, you will see two connection are available dataSource and delegate. Drag dataSource to the table view . Do it once more time for the delegate. Save it and go back to the Xcode.

Step 9: In the TableView.m file make the following changes:




Step 10: Compile and run the application in the Simulator.

You can downloaded SourceCode from here CheckMark 2

Comments 9

  1. Hi Guys

    This is a great tutorial got it working straight away with own data, but the next biggest question for this tutorial would be how would you make this data persistent.

    Thanks for the help, Brad

    • I tried this but it wouldn’t save the bool value for the checked state just the text and then starts the value back at 0.


  2. Hi,

    This tutorial is best. I used ur logic with my logic and requirement , but i have facing a problem. My problem is ,when i check my last index then my first index is automatically unchecked.
    How to unchecked my First index when i checked my last index and Vice Versa also ?

  3. There is a bug. You accessory button intercepts touch and does not propagate it to UITableViewCell. Meaning it will no select the cell if your user touches accessory view.

Leave a Reply

Your email address will not be published. Required fields are marked *