Welcome, Guest
Username Password: Remember me

Add Disclosure button to cells
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Add Disclosure button to cells

Add Disclosure button to cells 1 year, 2 months ago #1

Hello,
I just purchased STV and so far, I must say I am amazed at how easy it is so far. Watched the videos, and within about 10-15 minutes I had a basic app running that would have taken my hours to do without STV.

I am trying to figure out how to add a Detail Disclosure button to my table.

To give you an analogy of what I am trying to do, I have the following entities: State, County, and City. So far, I have my app setup following the basic structure of the Core Data sample app, and have the State entity implemented so far. When the Detail Disclosure button is selected, I want the State detail view to display. When the cell is selected, I want to drill-down and display all of the Counties in the selected State.

With a UITableViewCell, I was using cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton in the cellForRowAtIndexPath method. Then in the didSelectRowAtIndexPath method, I would push the Cities view controller onto the navigation stack. In the accessoryButtonTappedForRowWithIndexPath method, I would push the State detail view onto the navigation stack.

Any assistance you can provide would be greatly appreciated.

Thank you,
Troy
  • TroyP
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Karma: 0

Re: Add Disclosure button to cells 1 year, 2 months ago #2

Hi Troy,

Thanks a lot for all the complements

You can do what you're asking for through STV's SCTableViewModelDelegate methods (please make sure you conform to the SCTableViewModelDelegate protocol in your view controller's header file). First, you need to implement the willConfigureCell method:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willConfigureCell:(SCTableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Make sure the current section is an SCArrayOfObjectsSection before
// modifying the cell's accessory type
SCTableViewSection *section = [tableViewModel sectionAtIndex:indexPath.section];
if([section isKindOfClass:[SCArrayOfObjectsSection class]])
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
 


This will actually modify the cells in the main model only, and not the rest of the detail models' cells. This is because only the main model has its "delegate" property set automatically to your view controller. To have the "willConfigureCell" method get called for the rest of the detail models, you'll have to set their delegates using the following methods:

 
// Method is called when a detail model is created for a new item
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailModelCreatedForSectionAtIndex:(NSUInteger)index
detailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
detailTableViewModel.delegate = self;
}
 
// Method is called when a detail model is created for an existing item
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailModelCreatedForRowAtIndexPath:(NSIndexPath *)indexPath
detailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
detailTableViewModel.delegate = self;
}
 


With STV 2.0 final release (due before the end of this week), STV would automatically use the disclosure button to display the cell's detail view and you would be done here. Since you don't have the final release yet, you should manually tell STV to do that:

 
// Tell STV what to do when the disclosure button is tapped
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
SCTableViewSection *section = [tableViewModel sectionAtIndex:indexPath.section];
 
// check if the section in an SCArrayOfObjectsSection
if([section isKindOfClass:[SCArrayOfObjectsSection class]])
{
SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)section;
 
// Tell the section to dispatch the same event as if the cell itself was selected
[objectsSection dispatchSelectRowAtIndexPathEvent:indexPath];
}
}
 


Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Add Disclosure button to cells 1 year, 2 months ago #3

Thank you for the quick response. I'm still trying to figure out how to code the didSelectRowAtIndexPath method. I've already tried searching the forums, so if you have already helped someone else with this, I apologize. I'm probably trying to over complicate things since I'm accustomed to doing this the old way using fetchedResultsController.

Thanks again.
Troy
  • TroyP
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Karma: 0

Re: Add Disclosure button to cells 1 year, 2 months ago #4

Hi again Troy,

Never mind at all!

Most of the time you won't need to do this while using STV, but if you do need to be informed when a cell gets selected, just implement the SCTableViewModelDelegate method called didSelectRowAtIndexPath:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// your code here
}
 


As I already said, most of the time STV takes care of everything for you, so you'd usually only implement this if you want to present your own custom view controllers or something. Please tell me if you need anything else.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Add Disclosure button to cells 1 year, 2 months ago #5

Hi Tarek,
In the didSelectRowAtIndexPath, this is what I have so far:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SCTableViewSection *section = [tableViewModel sectionAtIndex:indexPath.section];
 
SCArrayOfObjectsSection *stateSection = (SCArrayOfObjectsSection *)section;
 
NSManagedObject *stateObject = [stateSection.items objectAtIndex:indexPath.row];
 
//I added an alert to indicate that I have correctly retrieved the selected State.
//Trying to now display a SCTableViewModel listing the County entities for the selected stateObject. Based on what you shared with me earlier, the accessoryButtonTappedForRowWithIndexPath method is handling the default action for didSelectRowAtIndexPath.
 
}


Thanks again for all of your help.

Troy
  • TroyP
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Karma: 0

Re: Add Disclosure button to cells 1 year, 2 months ago #6

Hi Troy,

Glad everything is working well for you now. Please tell me if you need anything else.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 1.91 seconds