UA-17470720-3

Jump to content


Photo
- - - - -

Really simple SCCustomCell Example

cells

  • Please log in to reply
4 replies to this topic

#1 notreallyme

notreallyme

    Experienced Member

  • STV 5.0 Pro
  • PipPipPipPip
  • 82 posts
Reputation: 8
Good

Posted 07 October 2012 - 01:11 PM

Hello,

i just wanted to present a list with custom cells with a dynamic UILabel in it, which i predefine by simple NSMutableArray of NSStrings . Reading the example and the documentation of SCCustomCell i get the impression that it is only possible to achieve this simple task in a complicated way, namely by using core data. I dont want to create a database to get a simple table with strings presented. Is there a more simple possibility to present a list of custom cells with a dynamic UILabel in them?

Regards, Helmut.

#2 cometlinear

cometlinear

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 55 posts
  • LocationCalifornia
Reputation: 10
Good

Posted 07 October 2012 - 07:31 PM

You don't need to use Core Data. You can use any subclass of SCDataDefinition. SCClassDefinition is one of the most commonly used.

#3 notreallyme

notreallyme

    Experienced Member

  • STV 5.0 Pro
  • PipPipPipPip
  • 82 posts
Reputation: 8
Good

Posted 08 October 2012 - 12:17 AM

Thanks for the suggestion. This is still too complicated for what i need here. I just want to have some cells with a custom layout (actually they will work as buttons) and i want to set a simple text attribute in them in code. Without using STV i would create the cell from the NIB like this:


[[NSBundle mainBundle] loadNibNamed:@"PreferencesCellButton" owner:self options:nil];


and set the label in it like

self.buttonCell.Label = @"ButtonText";

How can i simply achieve this using STV?

#4 cometlinear

cometlinear

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 55 posts
  • LocationCalifornia
Reputation: 10
Good

Posted 08 October 2012 - 07:51 PM

You have many options. You can create a section bound to an object, where each property has its own cell. You can bind the section to an Dictionary if you want, and each item in the dictionary will have its own cell. You can also just create cells manually, and add them to a section. Then add the section to the table view model.

Table view model -> section -> cells.

Read the book. Seriously. Page 64 explains how to edit the cell label.

#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 08 October 2012 - 08:10 PM

Hi Helmut,

Joshua is right, you don't need to use Core Data at all. If all you need is to display a list of static strings and have the cells act like buttons, then SCArrayOfStringsSection is your perfect fit. Here is an example:

- (void)viewDidLoad
{
  NSMutableArray *menuItems = [NSMutableArray arrayWithObjects:@"Item 1", @"Item 2", @"Item 3", nil];
 
  SCArrayOfStringsSection *menuSection = [SCArrayOfStringsSection sectionWithHeaderTitle:@"Select Item" items:menuItems];
  // add an action to implement custom behavior when the cells are tapped
  menuSection.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
  {
	 switch(indexPath.row)
	 {
		  case 0: // 1st menu item
			   // do custom action
			   break;
		 case 1: // 2nd menu item
			   // do custom action
			   break;
		 case 2: // 3rd menu item
			   // do custom action
			   break;
	 }
  }
  [self.tableViewModel addSection: menuSection];
}

Of course if you need to have custom Xib cells generated instead of the standard ones, just implement the sectionActions.cellForRowAtIndexPath action, as discussed in the book in great detail. Hope this helps.
  • cometlinear likes this





Also tagged with one or more of these keywords: cells

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users