Welcome, Guest
Username Password: Remember me

Insert Non-Bound Cell into SCArrayOfObjectsSection
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Insert Non-Bound Cell into SCArrayOfObjectsSection

Insert Non-Bound Cell into SCArrayOfObjectsSection 1 year, 5 months ago #1

Hi All,

My STV is bound to Core Data and thus defined in a SCClassDefinition which is then generated into a SCArrayOfObjectsSection using the + sectionWithHeaderTitle:withEntityClassDefinition: method.

This generates a nice STV which displays each object in the Core Data entity and, when tapped, produces a detail view allowing for the relevant attributes of the object to be edited. Say that I want to put a non-bound cell in the detail view. For example, an table view cell with just a label. In other words, the cell is not bound to any object attribute from Core Data. How would I go about doing this?

Going one step further, if I wanted to make a completely custom cell and insert that into the detail table view (also not bound to a Core Data attribute) would STV 2.0 allow this to happen (through designing the cell in IB)?

Thanks,
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2

Re: Insert Non-Bound Cell into SCArrayOfObjectsSection 1 year, 5 months ago #2

Hi Matthew,

You can add any additional cells/sections you want inside the "tableViewModel:detailViewWillAppearForRowAtIndexPath:withDetailTableViewModel:" method. Here is a code sample illustrating adding an additional SCLabelCell:

- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewWillAppearForRowAtIndexPath:(NSIndexPath *)indexPath
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
SCLabelCell *labelCell = [SCLabelCell cellWithText:@"Label Cell"];
labelCell.label.text = @"My label";
[detailTableViewModel sectionAtIndex:0] addCell:labelCell];
}


Going one step further, if I wanted to make a completely custom cell and insert that into the detail table view (also not bound to a Core Data attribute) would STV 2.0 allow this to happen (through designing the cell in IB)?


Sure, that can be created using the exact same code as above. Just create an SCControlCell as in the "Custom Cells App" sample application and add it to the detail section. Please tell me if you need any more help.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Insert Non-Bound Cell into SCArrayOfObjectsSection 1 year, 5 months ago #3

Hi Tarek,

I knew that there had to be an easy way Thanks for getting back to me so quickly.

One thing that may be useful for others (which had me stumped for a while) is that if you want the SCTableViewCellDelegate methods to be called make sure you set the delegate of the cell. Using Tarek's example above, this would be:

labelCell.delegate = self;

Now all of the willConfigureCell:, didDisplayCell:, etc. delegate methods will be called, if implemented.

Thanks,
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2

Re: Insert Non-Bound Cell into SCArrayOfObjectsSection 1 year, 5 months ago #4

That is correct Matthew

You can also have the cell delegate automatically assigned for you by the class definition via its uiElementDelegate property. For an example of this, please check out this post: www.sensiblecocoa.com/forum/sensible-tab...-properties.html#185
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Insert Non-Bound Cell into SCArrayOfObjectsSection 1 year, 5 months ago #5

Thanks Tarek. I have done that for the SCClassDefinition itself, but if I then add a new cell to that section (using the method which you outlined) then the delegate methods are not called on that new cell unless I explicitly set the delegate for the cell. It seems that the cell does not pick up the delegate setting from the SCClassDefinition, presumably because the cell is being added to the section later, rather than being automatically generated as part of the class definition.

Thanks,
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2

Re: Insert Non-Bound Cell into SCArrayOfObjectsSection 1 year, 5 months ago #6

That's the correct behavior Matthew. The uiElementDelegate property is only applicable to cells automatically generated by the class definition. Cells added manually are given the freedom to have their delegate property set to the value of their creator's choice.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 1.56 seconds