Welcome, Guest
Username Password: Remember me

Fonts and default data
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Fonts and default data

Fonts and default data 1 year, 7 months ago #1

Hi,

Great product!! I've looked in the forums back cant find anything on this, but 2 questions :
1. Can you change the default font of the editable data area in a table cell ?? Preferably when you setup the property definitions ?? I can modify the label font easily enough through willDisplayCell.
2. Also is there the ability to populate a cell with default data, i.e. I have a DatePicker assigned to a cell via SCPropertyTypeDate, but instead of the user selecting the latest date/time I'd prefer to just show them the current date at the tablecell level without having to select the Picker.

Thanks heaps!!
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Fonts and default data 1 year, 7 months ago #2

1- You can do that too from willDisplayCell, here is some code:

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


Is this what you're looking for?


2- Any object bound cell gets its default data from its initial bound property value, so you can simply assign the date to the bound property and SCDateCell will default to it.

Hope this helps
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Fonts and default data 1 year, 7 months ago #3

Cool thanks.

So is it possible to do that customisation of the cell though when setting up the table and its definitions or can it only be done through willDisplayCell ??

COuld you elaborate on the second point. I use Core Data objects, with class and property definition as follows ??

SCClassDefinition *inspectionDef =
[SCClassDefinition definitionWithEntityName:@"Inspection" withManagedObjectContext:managedObjectContext withPropertyNames: [NSArray arrayWithObjects:@"address", @"suburb", @"state", @"inspectionDate", @"inspectionType", @"inspector", @"areas", nil] ];

SCPropertyDefinition *datePropertyDef = [inspectionDef propertyDefinitionWithName:@"inspectionDate"];
datePropertyDef.type = SCPropertyTypeDate;
datePropertyDef.attributes = [SCDateAttributes attributesWithDateFormatter:dateFormatter];

Can I set a bound value in the Property Definition somehow then ??
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2

Re: Fonts and default data 1 year, 7 months ago #4

1- For a thorough discussion on customizing STV cells please check out these two posts:
www.sensiblecocoa.com/forum/general-disc...e-table-cell.html#12
www.sensiblecocoa.com/forum/sensible-tab...-properties.html#185

2- You don't set the default value in the property definition, but rather in the managed object itself. Core Data STV defaults can be set in two main ways:

a. You can set the default value for any attribute from the Core Data model designer, and STV will work with that.

b. If you need to determine the default value at runtime (getting the current date for example), you need to implement the SCTableViewModelDelegate method called tableViewModel:itemCreatedForSectionAtIndex:item:. This method gets called when a managed object is first created, typically when the user taps the add button. Here is some code sample that illustrates how to achieve what you want:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
itemCreatedForSectionAtIndex:(NSUInteger)index
item:(NSObject *)item
{
// This step is not technically necessary but I have it just for clarity.
NSManagedObject *managedObject = (NSManagedObject *)item;
 
[managedObject setValue:[NSDate date] forKey:@"inspectionDate"];
}
 
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Fonts and default data 1 year, 7 months ago #5

Perfect!! Great help as usual Tarek. Thanks!!
  • monsta
  • OFFLINE
  • Expert Boarder
  • Posts: 130
  • Karma: 2
  • Page:
  • 1
Time to create page: 0.98 seconds