Welcome, Guest
Username Password: Remember me

STV generated detail view without STV
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: STV generated detail view without STV

STV generated detail view without STV 1 year, 4 months ago #1

Hi All,

The subject of this message is somewhat cryptic, so allow me to explain. While I am using STV for most of the table views within my app, a few of the table views are simply so customised (for one reason or another) that I unfortunately cannot use STV. However, I still need the same behaviour that STV offers in the way of detail views within these customised table views.

Is it possible to ask STV to generate detail views for the rows in a standard UITableView? The table view data is being sourced from Core Data, loaded into an array for the cell generation in the tableView:cellForRowAtIndexPath: method. I realise that I would need to handle quite a few things provided automatically by STV (e.g. indicating that the root table view needs to be updated when data within the detail views has changed, etc.) but I can manage those. I mainly just need the automatically generated detail views, so I don't need to "reinvent the wheel" and manually create detail views just for these non-STV table views.

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

Re: STV generated detail view without STV 1 year, 4 months ago #2

Hi Matthew,

Sure, you can have STV work as the detail view of normal UITableView cells. However, before going into that, I wish if you can share with me why you're not using STV as your main table view. I really can't think of a case where STV can't be used instead of a normal UITableView, and I will most probably be able to help you to do just that. Of course, if you still just want to use a normal UITableView, please tell me and I'll give you details on how to achieve what you want
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: STV generated detail view without STV 1 year, 4 months ago #3

Hi Tarek,

Thanks for your quick reply. Don't get me wrong, STV is awesome for 99% of my application. However, in one table view I have done some very significant customisation to achieve specific behaviour for my use-case. Most specifically, I am using custom UITableViewDelegete and UITableViewDataSource classes and overriding quite a few of the standard methods. It would be difficult for me to go into the exact details here, but I need to generate the cells in a very particular way for the desired behaviour and thus have needed to use a standard UITableView.

I am in a bit of a hurry to get the app released, so at this point I think that I will need to stick with the standard UITableView with STV generating the detail view, so if you could provide some details on achieving this outcome that would be great.

[That said, in slower time, once the app has been released, I would welcome the opportunity to speak with you further about ways to get this unique table view across to using STV, as it would be good to get total uniformity of using STV across the app. Unfortunately I just don't have the time at the moment to re-do the existing work.]

While I have got you, a second (somewhat related) question. Say that I have a detail edit view for an STV which allows the user to edit all attributes of that row (it's bound to Core Data). For sake of argument, the attributes are First Name, Last Name, Age, Phone Number (the only mandatory attributes are First Name and Last Name). If the user taps the Add (+) button to add a new row, I only want them to be able to specify the First Name and Last Name in this Add view. Then, if they want to modify the Age and Phone number they must tap the newly created row to enter the detail edit view and do it through there. Is this possible?

Thanks again Tarek!
Matthew
  • skoota
  • OFFLINE
  • Expert Boarder
  • Posts: 89
  • Karma: 2

Re: STV generated detail view without STV 1 year, 4 months ago #4

No problem Matthew, I understand

It's actually really simple to use STV from a normal UITableView.

1- Create the detail view controller subclass as you would normally do for your root view controller. The detail view should have the table model defined in its header file, then initialized in viewDidLoad (you will probably not need to add any sections to the model at this point). All this is exactly what you do when you use STV in the RootViewController, there is nothing new here. The only difference is that you should create a @property to give access to the tableModel from outside the class, as you'll probably need that later (see below). For the sake of this discussion, I'll refer to this detail view controller as DetailViewController.

2- In the view controller that uses the normal UITableView, implement the UITableViewDelegate method called didSelectRowAtIndexPath to push the DetailViewController.

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// I am assuming here that DetailViewController is a subclass of UITableViewController
DetailViewController *myDetailView = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
 
// You'll probably need to add an SCObjectSection to the detail model
SCObjectSection *objectSection = [SCObjectSection sectionWithHeaderTitle:nil
withBoundObject:myObject withClassDefinition:myObjClassDef];
[myDetailView.tableModel addSection:objectSection];
 
// Push the detail view normally here (assuming self is within a UINavigationController)
[self.navigationController pushViewController:myDetailView animated:TRUE];
[myDetailView release];
}
 


That should be about it. Please tell me if you still have questions regarding this.


If the user taps the Add (+) button to add a new row, I only want them to be able to specify the First Name and Last Name in this Add view. Then, if they want to modify the Age and Phone number they must tap the newly created row to enter the detail edit view and do it through there. Is this possible?


The easiest way to do this is by implementing the SCTableViewModelDelegate method called detailViewWillAppearForSectionAtIndex and removing the automatically generated Age & Phone cells.

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewWillAppearForSectionAtIndex:(NSUInteger)index
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
SCObjectSection *objectSection = (SCObjectSection *)[detailTableViewModel sectionAtIndex:0];
 
// Assuming the cells order in the class definition is "First Name, Last Name, Age, Phone"
[objectSection removeCellAtIndex:3]; // Phone Cell
[objectSection removeCellAtIndex:2]; // Age Cell
}
 


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

Re: STV generated detail view without STV 1 year, 4 months ago #5

Thanks Tarek I'll check this out and let you know how it goes.

By the way, happy new year to all!

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

Re: STV generated detail view without STV 1 year, 4 months ago #6

Happy new year Matthew!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 1.86 seconds