Welcome, Guest
Username Password: Remember me

Subclassing SCTableViewCell
(1 viewing) (1) Guest

TOPIC: Subclassing SCTableViewCell

Subclassing SCTableViewCell 1 year, 7 months ago #1

Hi All,

First, let me say how much Sensible TableView has helped me. It has taken me just a few hours to do something that was going to take me several weeks. I'm one happy customer!

Now onto the question. I need to create some custom cells (with various combinations of controls) to be served-up by Sensible TableView. I am comfortable with subclassing SCTableViewCell to create my own cells, but I am unsure about how to tell Sensible TableView to use these cells.

Here is a fairly straight-forward example (please don't poke holes in why I am using certain controls to display certain information - this is just an example). I have a Core Data entity called Person with two attributes: name and age. Say that I create a subclass of SCTableViewCell called MyLabelAndButtonCell for use in the detail editing view of a Sensible TableView that displays all of the entities in Person. This new cell has a UILabel on the left-hand side to display the attribute name (e.g. Name) and a UIButton on the right, whose titleLabel needs to display the value of the attribute (e.g. Joe Bloggs). In my implementation of Sensible TableView it automatically generates the cells for each row in the detail editing view.

So, two questions arise from the above:

1. How can I tell Sensible TableView to use MyLabelAndButtonCell instead of the default SCTableViewCell in the detail editing view?

2. How do I link the attribute name and value to the correct controls? In this example, how do I tell Sensible TableView that the attribute name should appear as the UILabel text and the attribute value should appear as the UIButton titleLabel?

Thanks again for any help that you can provide!
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2

Re: Subclassing SCTableViewCell 1 year, 7 months ago #2

Hi Matthew, thanks a lot for your complements!

What you're discussing is exactly the highlight of our next release (also briefly discussed here: sensiblecocoa.com/forum/sensible-tablevi...it=6&start=6#649). Not only will you be able to create your own custom cell controls and connect them to Core Data attributes or bind them to object properties, but you'll also be able to create all these custom controls in Interface Builder too!

If you want, I can send you a beta version of this in about 3 weeks from now. Thanks a lot for your feedback.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Subclassing SCTableViewCell 1 year, 7 months ago #3

Hi Tarek,

Thanks for your reply. If you could send through the Beta when it's ready that would be great - I am happy to do some testing for you of this new feature.

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

Re: Subclassing SCTableViewCell 1 year, 7 months ago #4

Hi Tarek,

Another quick question relating to subclassing SCTableViewCell. Am I able to create a subclass of SCTableViewCell for use in the root STV (i.e. the cells which are displayed with the titlePropertyName and are then tappable to show the detail edit view)?

I was thinking that if I could use my own subclass then I could then tell STV the information that needs to be displayed within each custom control on my subclassed SCTableViewCell through writing the necessary code in the willConfigureCell: and willDisplayCell: delegate methods. However, I am unsure how to tell STV to use these cells rather than the standard SCTableViewCell (as all rows are being automatically generated from a Core Data entity).

Any suggestions would be great, or if this feature is not yet available that's also fine (I just wanted to make sure I wasn't spending time trying to get this working if it is not yet supported).

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

Re: Subclassing SCTableViewCell 1 year, 7 months ago #5

Hi Matthew,

In the new release we were discussing earlier, you will be able to tell SCClassDefinition which of your custom cells to use.

Having said that, if all you need is add some custom controls to one of STV's standard cells, you can still do that with the current version in willConfigureCell (no need for subclassing). It's just going to be so much easier to do that in the new release, especially that you'll be able to use Interface Builder too.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
Last Edit: 1 year, 7 months ago by tarekskr.

Re: Subclassing SCTableViewCell 1 year, 7 months ago #6

Hi Tarek,

Thanks for your quick reply. Yes, I have been experimenting with putting some custom controls into the willConfigureCell: method (as an interim measure until the next release of STV). Here is an example of some code which I included:

UILabel *castLabel = [[UILabel alloc] init];
castLabel.text = @"Test Label";
[cell addSubview:castLabel];


However, I have found that when I scroll the table view (and cell reuse kicks-in) that willConfigureCell: gets called on cells which have already had willConfigureCell: called causing multiple castLabels to be added to the cell, as the UILabel code is re-executed. Do you know a way around this issue?

Thanks,
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2
Time to create page: 1.01 seconds