Welcome, Guest
Username Password: Remember me

How to customize table cell
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: How to customize table cell

How to customize table cell 1 year, 9 months ago #1

How to customize table cell as per real-time applications. For example a table cell with an image, 2-3 labels, button and to handle click-event of button.
  • Chauhan
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Karma: 0

Re: How to customize table cell 1 year, 9 months ago #2

Sensible TableView cells can be fully customized using three main ways:

1. If you are creating the cells yourself and adding them to the section, then you can simply customize them using their properties. For example:
 
SCTextFieldCell *textFieldCell = [SCTextFieldCell cellWithText: @"Name" withPlaceholder: @"enter name" withBoundObject:myObject withTextFieldTextPropertyName: @"name"];
 
textFieldCell.height = 60;
textFieldCell.textField.backgroundColor = [UIColor clearColor];
textFieldCell.backgroudView = myBackgroundView;
textFieldCell.imageView = myImageView;
 


2. If you have Sensible TableView generate the cells for you, then you customize their appearance using delegates: Sensible TableView model (SCTableViewModel) fires two main methods to allow full cell customization:

a. tableViewModel:willConfigureCell:forRowAtIndexPath, which allows for customizing SCTableViewCell properties such as the height or editable. For example:
 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel willConfigureCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath
{
cell.height = 60;
cell.editable = FALSE;
cell.movable = FALSE;
}
 


b. tableViewModel:willDisplayCell:forRowAtIndexPath:, which allows for customizing everything relating to SCTableViewCell appearance. For example:
 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel willDisplayCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath
{
((SCControlCell *)cell).control.backgroundColor = [UIColor clearColor];
cell.backgroudView = myBackgroundView;
cell.imageView = myImageView;
}
 

Please also note that similar methods are also fired per individual cell if you conform to the SCTableViewCellDelegate.

3. For customizations such as adding buttons or more user controls to the cell, you can simply inherit from SCTableViewCell or any of its subclasses, then add all your controls.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: How to customize table cell 1 year, 9 months ago #3

Hi - Great product!

Btw, I am new to Objective-C and iDevice development.

My cells are generated from model, I am trying to figure out how to align the labels as left aligned, and values (textfield input) right aligned, I am trying to use the delegate approach but it doesn't look like the delegate method get fired..

I have the delegate method in my controller.m

- (void)tableViewModel:(SCTableViewModel *) tableViewModel willConfigureCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath

.....

And my Controller.h has delegate protocol declaration <SCTableViewCellDelegate>

Am I missing something?

And even if it fires, how do I customize a particular cell, i would probably have around 150 cells and I want to have different
customization for different sections?

Thanks
Muthu
  • Nat
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0

Re: How to customize table cell 1 year, 9 months ago #4

Hi Muthu:

First, for the delegate method to get fired, you must make sure that your view controller conforms to the SCTableViewModelDelegate protocol. To do that, in your view controller's header file, add <SCTableViewModelDelegate> after the class declaration:

@interface myTableViewController : UITableViewController <SCTableViewModelDelegate>


Now to configure individual cells from within tableViewModel:willConfigureCell:forRowAtIndexPath:, you'll need to check the indexPath parameter for the cell's index in your section. Next, you can cast the cell to it's correct class and do your customizations. This is a sample code snippet that illustrates how to change the cell's text field alignment:

 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel willConfigureCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath
{
if([cell isKindOfClass:[SCTextFieldCell class]])
{
SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell;
textFieldCell.textField.textAlignment = UITextAlignmentRight;
}
}
 


Please note that the textField property of SCTextFieldCell is just a normal UITextField (an Apple Cocoa Touch class), so you can set it up the same way that any UITextField is set up (please check Apple's documentation on that).

Hope this helps.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
Last Edit: 1 year, 9 months ago by tarekskr.

Re: How to customize table cell 1 year, 9 months ago #5

Thanks for the post! It is really helpful.
  • Nat
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0

Re: How to customize table cell 1 year, 9 months ago #6

Appreciate any help on the following issue..

As I mentioned earlier I am generating the cells from modal, however when I try scroll the app just freezes and it seems like it is failing in the following method

SCTaleViewCell -line 408
//override superclass
- (void)willDisplay
{
[super willDisplay];

if(!self.needsCommit)
[self loadBoundValueIntoControl]; //-- fails here
}

- (void)loadBoundValueIntoControl
{
// Does nothing, should be overridden by subclasses
}

@end
  • Nat
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0
  • Page:
  • 1
  • 2
Time to create page: 2.04 seconds