Hello.
I have CoreData model where are two entities got the same parent. My goal is to show two different cells filled up with two different types of objects in the same tableView.
Usually it could be easily achieved by using cellForRowAtIndexPath that returns cell type based on FRC current object. But how it can be done using STV? Is it possible to do with storyboard/xib or some other way?

#1
Posted 26 October 2015 - 11:37 AM
#2
Posted 26 October 2015 - 11:48 AM
Hi mehdzor,
Several ways come to mind, but the easiest in my opinion is to add both cells in the IB entity definition, then selectively remove the desired cell at runtime depending on the specific entity. The runtime code may look something like this:
// MasterViewController.m - (void)viewDidLoad { [super viewDidLoad]; self.tableViewModel.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath) { SCTableViewSection *detailFirstSection = [detailModel sectionAtIndex:0]; if(myCheck) { [detailFirstSection removeCellAtIndex:myFirstCellIndex]; } else { [detailFirstSection removeCellAtIndex:mySecondCellIndex]; } }; }
Hope this helps.
#3
Posted 26 October 2015 - 12:39 PM
I mean for array of objects when amount of objects is unknown. This example is for detail mode.
Hi mehdzor,
Several ways come to mind, but the easiest in my opinion is to add both cells in the IB entity definition, then selectively remove the desired cell at runtime depending on the specific entity. The runtime code may look something like this:
// MasterViewController.m - (void)viewDidLoad { [super viewDidLoad]; self.tableViewModel.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath) { SCTableViewSection *detailFirstSection = [detailModel sectionAtIndex:0]; if(myCheck) { [detailFirstSection removeCellAtIndex:myFirstCellIndex]; } else { [detailFirstSection removeCellAtIndex:mySecondCellIndex]; } }; }
Hope this helps.
Edited by mehdzor, 26 October 2015 - 12:40 PM.
#4
Posted 26 October 2015 - 12:50 PM
Oh so you need different cells for the SCArrayOfObjectsSection itself? If so, then you should supply them in sectionActions.cellForRowAtIndexPath:
- (void)viewDidLoad { [super viewDidLoad]; self.tableViewModel.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath) { SCCustomCell *customCell = nil; if(myCheck) customCell = [SCCustomCell cellWithText:nil objectBindingsString:nil nibName:@"MyFirstCustomCell"]; else customCell = [SCCustomCell cellWithText:nil objectBindingsString:nil nibName:@"MySecondCustomCell"]; return customCell; }; }
Please let me know if this is what you're looking for.
#5
Posted 26 October 2015 - 01:02 PM
Almost! Two more questions:
- How do I get a type of the object at this row? To select cell type based on it. I read whole documentation for SCArrayOfItemsSection and SCTableViewModel but found nothing similar to receiving current object.
- How do I associate entity fields with cell labels and views when cell is created in xib? Where can I read about this?
Oh so you need different cells for the SCArrayOfObjectsSection itself? If so, then you should supply them in sectionActions.cellForRowAtIndexPath:
- (void)viewDidLoad { [super viewDidLoad]; self.tableViewModel.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath) { SCCustomCell *customCell = nil; if(myCheck) customCell = [SCCustomCell cellWithText:nil objectBindingsString:nil nibName:@"MyFirstCustomCell"]; else customCell = [SCCustomCell cellWithText:nil objectBindingsString:nil nibName:@"MySecondCustomCell"]; return customCell; }; }
Please let me know if this is what you're looking for.
Edited by mehdzor, 26 October 2015 - 01:08 PM.
#6
Posted 26 October 2015 - 01:22 PM
a. Inside the action block, you can access the object using: [itemsSectio.items objectAtIndex:indexPath.row].
NSManagedObject *detailObject = (NSManagedObject *)[itemsSection.items objectAtIndex:indexPath.row]; NSString *entityName = [detailObject entity].name;
b. The easiest way to associate data to controls in custom cells is by using STV's 'Curly Brace Binding'. Using curly brace binding, you simply set the label's text to the property name you wish it to bind to, while enclosing it with curly braces, and STV will automatically bind the label's data to this property (e.g.: {propertyName} ). You can find a detailed example in our Custom Cells video, in addition to a detailed tutorial in the Exploring Web Service Binding part of STV's user manual. Finally, you can find several bundled STV samples that use this technique, including CalculatedCellsApp and WebServiceApp.
- wizgod and mehdzor like this
#7
Posted 26 October 2015 - 02:47 PM
Thanks a lot for help!
a. Inside the action block, you can access the object using: [itemsSectio.items objectAtIndex:indexPath.row].
NSManagedObject *detailObject = (NSManagedObject *)[itemsSection.items objectAtIndex:indexPath.row]; NSString *entityName = [detailObject entity].name;
b. The easiest way to associate data to controls in custom cells is by using STV's 'Curly Brace Binding'. Using curly brace binding, you simply set the label's text to the property name you wish it to bind to, while enclosing it with curly braces, and STV will automatically bind the label's data to this property (e.g.: {propertyName} ). You can find a detailed example in our Custom Cells video, in addition to a detailed tutorial in the Exploring Web Service Binding part of STV's user manual. Finally, you can find several bundled STV samples that use this technique, including CalculatedCellsApp and WebServiceApp.
#8
Posted 26 October 2015 - 02:49 PM
You're most welcome!
Also tagged with one or more of these keywords: cells, core-data
Sensible TableView Forum →
STV Cells →
Change Highlighted Color on Touch DownStarted by wizgod , 12 Mar 2017 ![]() |
|
![]()
|
||
Sensible TableView Forum →
STV Model →
SCTableModel's boundObject's dealloc method not calledStarted by tommy@ageet , 12 May 2016 ![]() |
|
![]()
|
||
Sensible TableView Forum →
STV Model →
Rearranging the cells of the table and fetching their orderStarted by fabiensen , 27 Apr 2016 ![]() |
|
![]()
|
||
Sensible TableView Forum →
STV Cells →
Cell in SCArrayOfStringsSection not showing selectionStarted by RaduGrama , 08 Mar 2016 ![]() |
|
![]()
|
||
Sensible TableView Forum →
Sensible Table View Controllers →
DetailViewController cells too narrowStarted by Dennis , 11 Dec 2015 ![]() |
|
![]()
|
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users