Thursday, June 23, 2016

Create Custom Cell Using XIB With Protocol(Call back method) in swift

I will show you how to customize table view cells by using static xib and by subclassing UITableViewCell in Swift.

Create a Empty project and next create a subclass with xib named by CustomTableCell.
In next three screen follow the code(don't forgot delegate 'CustomTableCellDelegate') and design the xib.

Also create a uibutton action

In your viewcontroller implement cell delegate and tableview datasource and delegate also
and follow the screens

if you create a cell without Register cell close 'option 1' and open 'option 2' codes


And in viewcontroller xib 


every thing is done now just run your project





Sunday, June 12, 2016

Create Custom Cell Using XIB With Protocol(Call back method)

I will show you how to customize table view cells by using static xib and by subclassing UITableViewCell. 
First, create a new project. In Xcode Click File ->New ->Project ->Single View Application

Set up the rest as in the picture below and click Next (I put project name CellProject)

The next step is to create a custom UITableViewCell. Right-click your project name node in the Project Navigation view and choose ->New File ->Cocoa Touch Class.

Set Class for you cell (I put here CustomTableViewCell) and must be subclass to UITaleViewCell and conform check Also create XIB file option.

And also I create protocol for button action it gave me callback on my view when I click any button.


Be sure to have Outlet type of the connection selected. Name the property valueField

We are going to create a value object based on NSObject class for hold data. In my case I am using User model.

Now, In ViewController class and stroyboard and I add all the necessary like, tableview add table view delegate and custom cell delegate. And add a dummy data method. and run the app

And finally you got this :)