iPhone SDK Tutorial – {Part 5}: Add, Delete & Reorder UITableView Rows

iPhone SDK Tutorial – {Part 5}: Add, Delete & Reorder UITableView Rows

This tutorial will explain, how you can change the UITableView data. In this tutorial, I will add, delete and re-order rows in UITableView. I will be using navigation code here.

Related posts:

  1. iPhone Programming Tutorial: {Part 3} Grouped UITableView I am going to write series of UITableView tutorials (Video…
  2. iPhone Programming Tutorial – {Part 1} UITableView using NSArray Creating iPhone Tutorial Introduction: I am going to write series…
  3. iPhone Programming Tutorial: Part 6: Creating custom UITableViewCell Using Interface Builder [UITableView] This tutorial will help you to create custom rows in…


iPhone Programming Tutorial: Part 6: Creating custom UITableViewCell Using Interface Builder [UITableView]

Introduction:

I am going to write series of UITableView tutorials (Video Tutorials as well). My target is to make the customized UITableView using UITableViewCell which is requested on “Request Tutorial” page. Following are the list of tutorials, which I will be posting on this blog:

1. Create a Simple UITableView [Populate UITableView With Array]
2. Navigatation in UITableView [Navigatation on UITableView using didSelectRowAtIndexPath]
3. Grouped UITableView [Using Interface builder]
4. Tips for UITableView Design [Change UITableView properties i.e background colour, accessory type, add footer and header]
5. Add, Delete & Re-order UITableView rows
6. Creating UITableView using UITableViewCell
7. Adding Pictures into your UITableView using Interface builder
8. UITableView & UITableViewCell examples and tips

[Note: If you want more tutorials on UITableView or UITableViewCell, then add a comment on “Request Tutorial” Page]

Idea of this tutorial:

UITableViewCell tutorial will explain how you can use UITableViewCell in UITableView. Custom UITableViewCell using Interface builder makes table view design very easy. Using UITableViewCell gives you lot of customization over the design of each row. You can easily reduce number of code lines by using UITableViewCell (i.e reduce customization code and easy to manage your table). There are few things which are little hard to do using UITableView but using UITableViewCell they are easily manageable i.e you can manage your cell code in a separate class, you can change the design of cell using nib files more easily then writing codes. So in my point of view, custom UITableViewCell using Interface builder makes your life more easy while developing applications for iPhone.

So in this tutorial, i will write only UITableViewCell and link it with UITableView. I will be using part 2 code, which you can grab from here. Final output of this code will be same as part two but to change the design on table will be really simple. You can watch the video tutorial at the end to skip all the text.

customize UITableView using UITableViewCell
customize UITableView using UITableViewCell

Steps to follow

Follow these steps to achieve the output like above:

Step 1: Open the SimpleTable project in Xcode (you can grab this code from here. [Note: I am using UITableView part 2 code here]). In Xcode, ‘Group and Panel’ right click on classes, select >Add> New File..>. Now select UITableViewCell and name it ‘TableViewCell’, press finished.

Add UITableViewCell
Add UITableViewCellSelect UITableViewCell from wizard
Select UITableViewCell from wizard

Name the UITableViewCell class
Name the UITableViewCell class

Step 2: Now in ‘TableViewCell.h’ file add following code before @end and after #import:

1.@interface TableCellView : UITableViewCell {
2.IBOutlet UILabel *cellText;
3.}
4.
5.- (void)setLabelText:(NSString *)_text;

Step 3: Now open ‘TableViewCell.m’ file and write a setter method for label like this:

1.- (void)setLabelText:(NSString *)_text;{
2.cellText.text = _text;
3.}

Step 4: Open SimpleTableViewController.h file and write following:

1.#import "TableCellView.h"
2.@interface SimpleTableViewController : UIViewController {
3.IBOutlet UITableView *tblSimpleTable;
4.NSArray *arryData;
5.IBOutlet TableCellView *tblCell;
6.}

Step 5: Open SimpleTableViewController.h file and import ‘TableCellView.h’ at top.

1.#import "TableCellView.h"

In cellForRowAtIndexPath method remove all the code or either comment the code. Add the following code in that method:

01.static NSString *MyIdentifier = @"MyIdentifier";
02.MyIdentifier = @"tblCellView";
03.
04.TableCellView *cell = (TableCellView *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
05.if(cell == nil) {
06.[[NSBundle mainBundle] loadNibNamed:@"TableCellView" owner:self options:nil];
07.cell = tblCell;
08.}
09.
10.[cell setLabelText:[arryData objectAtIndex:indexPath.row]];
11.return cell;

Step 6: Now open NextView.xib file from your Xcode project. Press cmd + shift + s to save as this file, and give it a name TableViewCell and ‘Add’ to ‘SimpleTable’ project:

Save As nib file
Save As nib fileSave As nib file
Name UITableViewCell xib file
Save As nib file
Save nib file

Step 7: Now in TableViewCell.xib file, select ‘View’ and then select Edit>Delete (or press ‘back space’ button) to remove the View from xib file

Save As nib file
Remove View from TableCellView.xibSave As nib file
Deleted View from TableCellView

Step 8: Now press cmd + shift + l to open Library. Drag ‘Table View Cell’ to ‘TableViewCell.xib’ file. Select ‘Table View Cell’ and press cmd + 4 and write ‘TableCellView’ in class and press cmd + 1 and write ‘tblCellView’ in Identifier.

Save As nib file
Add UITableViewCell to nib fileSave As nib file
Assign Class to Table Cell View

Save As nib file
Add Identifier to Table Cell View

Step 9: Now select ‘Files Owner’ and press cmd + 4 and type ‘SimpleTableViewController’ in class. Also press cmd + 2 and drag tblCell to ‘Table View Cell’ like in the below picture:

Save As nib file
Give class name to File’s Owner
Save As nib file
Map UITableViewCell to Table View Controller

Step 10: Now drag a label inside UITableViewCell and select ‘TableViewCell’, drag cellText with label.

Save As nib file
Map Label

Step 11: Save the interface builder and your code. Run the application and you will see the output like this:

Save As nib file
Custom UITableViewCell Output

Looked at bottom pictures to change the color of labels and cell Accessory:

Save As nib file
Change Table Cell View Accessory

Save As nib file
Change Label Text colour

Save As nib file
Label Colour text change

Run the application and you will see the final output.

Save As nib file
Final Output of Custom UITableViewCell

Custom UITableViewCell code

You can grab this code from here.

Now watch me doing it


iPhone Tutorial for Creating a Splash Screen

iPhone Tutorial for Creating a Splash Screen

Introduction:
Some people asked me about creating a splash screen in iPhone. So today I am going to write a simple tutorial on creating splash view for your application. I will write another post on good looking splash page as well. Its really a small thing but have a really good impact on your users.

So lets […]

Related posts:

  1. iPhone Programming Tutorial: Part 6: Creating custom UITableViewCell Using Interface Builder [UITableView] This tutorial will help you to create custom rows in…
  2. iPhone Programming Tutorial {Part 7}: Adding Pictures into your table using Interface builder Creating iPhone Application: Introduction: I am going to write series…
  3. iPhone Tutorial for Retrieving Contact information from AddressBook Introduction In this tutorial I will explain how you can…


Beginner iPhone SDK Hello World Tutorial [Example & Code]

In this tutorial I will walk to you through creating a simple “Hello World” application using interface builder. There are many ways that a Hello World program could be made on the iPhone, I am going to show you the simplest.

Related posts:

  1. Getting Started with iPhone Development Absolute Beginner’s Guide to iPhone Development | Getting Started with…
  2. Bypass Code Signature & Published Your Application on Cydia Published iPhone Application On Cydia. Build your application for jail…

Classified Ads Website

Classified Ads Website

The aim of this project is to make a classified ads website built in joomla. Below I state the keyfeatures of the project. Winning bid will get everything in full detail.

Keyfeatures of the project:

1) Users must be able to post their classified ad for free

2) There should be 3 types of classifieds: text, photo, video

3) All visitors should be able to view all kind of classifieds, but with no contact details of the submitter. Contact details should be revealed after a unique code is inserted into the system.

4) How somebody gets the code? With an sms. You have nothing to make about sms sending. The sms would be sent by a telecommunications company. The user that gets the code in his mobile phone inserts the code into the system and all classifieds’ contact details are revealed for a limited amount of time.

5) Administrator should be able to make different groups of codes with different time limits. Ex. Somebody inserts the code into the system. After this code is inserted for the 1st time it should expire after 24 hours(this can be 2 days, 5 days, or anything). Admin should be able to group those limits.

6) Two types of classifieds. Normal classifieds and classifieds about indebted products. I will explain in full detail to the winning bid.

7) A user can put his classified in featured classifieds by paying a small fee. So the user should be able to pay us online. Payment gateway for bank and paypal.

8) A flash map should be created. Not something difficult for a flash expert.

9) I need extended use of ajax and the website must have a web 2.0 feeling.

10) Everything should be controlled easily through the admin section. The admin section must also provide full reports about the website ex. total classifieds number and users’ statistcs.

Please bid only if you have extended joomla experience. High quality should be delivered in the least possible time limit.

Two things I will not tolerate and cancel the project. 1st) Exceed time limit (so please calculate your time wisely before bidding) and 2nd) Bad communication skills. If ask you something via email I demand an answer back.

If I am pleased of the work done then surely more projects to come. I am in need of a good programmer for longer time cooperation.