Augustyniak / RATreeView

Library providing easy-to-use interface for displaying tree structures on iOS and tvOS.
MIT License
2.49k stars 465 forks source link

Problems sub-classing UITableViewCell #203

Closed bottlehall closed 7 years ago

bottlehall commented 7 years ago

Hi,

I wrote an app using RATreeView a couple of years ago or so and recently decided to update and improve it.

I need to add at least one and sometimes two buttons to the tree view cell. The attached image shows what I have at the moment. I managed to do this using programmatic means on the earlier version, but it will simplify the code and make it work better in portrait mode (I think!) if I use a sub-classed UITableViewCell and auto-layout. img_0465 I've tried sub-classing and putting synthesised versions of textLabel and detailTextLabel and also using different names for these controls. No matter what I do, I can't get anything to display. The tree view still responds to taps and so will expand and collapse sections as normal, just nothing to see!

@interface SMItemTableViewCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UIButton buttonInclusion; @property (weak, nonatomic) IBOutlet UIButton buttonThumbnail; @property (weak, nonatomic) IBOutlet UILabel textLabel; @property (weak, nonatomic) IBOutlet UILabel detailTextLabel; @property (strong, nonatomic) id item;

@end

@implementation SMItemTableViewCell

@synthesize textLabel; @synthesize detailTextLabel;

@end

xib

Looking at the documentation for UITableView, it suggests I need to override initWithCoder and make sure that the table view has the custom class for the cell set in the view, etc. but none of this seems to apply to RATreeView. I have used debug to make sure the code is being executed and the buttons and labels are all being set to the correct values.

Any suggestions as to what I am doing wrong?

Thank you

Nick

bottlehall commented 7 years ago

Update:

I can now get something showing on the RATreeView, if I put this:

'- (UITableViewCell )treeView:(RATreeView )treeView cellForItem:(id)item { SMItemTableViewCell cell = [treeView dequeueReusableCellWithIdentifier:@"ItemCell"]; if (cell == nil) { NSArray nib = [[NSBundle mainBundle] loadNibNamed:@"SMItemTableViewCell" owner:self options:nil]; cell = (SMItemTableViewCell *)[nib objectAtIndex:0]; }

However, the indentation for the hierarchy is not there, so I guess RATreeView isn't actually using the sub-classed cell.

bottlehall commented 7 years ago

An astonishing degree of ineptitude, even allowing for the time of night of the OP, that I am too embarrassed to share.