UA-17470720-3

Jump to content


Photo
- - - - -

Table Cells from Core Data


  • Please log in to reply
10 replies to this topic

#1 hayden

hayden

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 06 October 2010 - 09:06 PM

Hi, I have an application where the data is stored in CoreData, and for each object I would like one cell in the Table view (displaying the Entities 'Title' attribute for example). Then when you click on a cell it will display/push another view based on what cell/object was selected (a web view).

Can Sensible Table View help with this situation? Any hints on how this is done (I already have CoreData setup and I have the objects in the table, however they display the wrong text in the cell, and when clicked it displays the other fields in the object, as the example video tutorial shows).

Any help or guidance will be appreciated.

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 07 October 2010 - 01:18 AM

Hi Hayden,

What you're describing sounds almost identical to the Core Data sample app we ship with STV. Would you please post your class definition code, in addition to which attribute you would like to appear as the cell's text? Thanks!

#3 hayden

hayden

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 07 October 2010 - 01:34 AM

Hi Tarek,

Here is the Class definition:

SCClassDefinition *userDef = 
	[SCClassDefinition definitionWithEntityName:@"User"
					   withManagedObjectContext:managedObjectContext
							  withPropertyNames:[NSArray arrayWithObjects:@"firstName",@"lastName",@"userId",nil]];
	
SCPropertyDefinition *firstNamePropertyDef = [userDef propertyDefinitionWithName:@"firstName"];
firstNamePropertyDef.title = @"First Name";
firstNamePropertyDef.type = SCPropertyTypeTextView;

SCPropertyDefinition *lastNamePropertyDef = [userDef propertyDefinitionWithName:@"lastName"];
lastNamePropertyDef.title = @"Last Name";
lastNamePropertyDef.type = SCPropertyTypeTextView;

SCPropertyDefinition *userId = [userDef propertyDefinitionWithName:@"userId"];
userId.title = @"userId";
userId.type = SCPropertyTypeNumericTextField;

I would like "$FirstName $LastName" to appear as the attribute. However when clicked I'd like it to display a UIView with a WebView or ScrollView based on what row was selected.

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 07 October 2010 - 03:02 AM

I'll send you now our latest RC version, where you'll be able to specify more than one attribute for the cell's title, each separated by a semi-colon. Here is the code you need to add to your class definition:

...
userDef.titlePropertyName = @"firstName;lastName";
...

To provide custom behavior when the cell is tapped, please refer to the following post: http://www.sensiblec...action.html#557

Hope this helps :)

#5 hayden

hayden

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 07 October 2010 - 03:24 AM

Thanks Tarek. One more thing, when I implement the delegate function

- (void)tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath

How do I get the User object that the indexPath.row corresponds to?

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 07 October 2010 - 03:28 AM

Here you go: http://www.sensiblec...aycell.html#502

#7 hayden

hayden

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 07 October 2010 - 04:18 AM

Again, thanks for your help Tarek.

#8 hayden

hayden

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 13 October 2010 - 09:08 PM

One more thing I just noticed, if I swipe over a cell it comes up with a delete button. Is this a way to disable this?
  • wizgod likes this

#9 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 15 October 2010 - 01:02 AM

What kind of section are you using Hayden?

1- If you're creating the cells yourself, all you need is set the SCTableViewCell "editable" property to FALSE.

2- If you're using an SCArrayOfObjectsCell or SCArrayOfObjectsSection, all you need is set the "allowDeletingItems" property to FALSE.

Hope this helps!
  • wizgod likes this

#10 hayden

hayden

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 1
Good

Posted 17 October 2010 - 04:38 PM

Thanks it works great.

Another thing, does SCT support easy indexing (e.g. A-Z on the right hand side of the screen, like in the Contacts app)?

#11 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 18 October 2010 - 04:18 AM

Sure, just set:

tableModel.sectionIndexTitles = [NSArray arrayWithObjects:@"A", @"B", ..., @"Z", nil];

(please check our Core Data sample application, under the "People" tab)

Alternatively, you can have STV automatically generate the section index titles by setting tableModel.autoGenerateSectionIndexTitles = TRUE (will only generate index titles for sections present in the table view).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users