
SCTableViewModel New vs Existing Objects
#1
Posted 17 September 2011 - 11:37 AM
However when I click the appropriate row on a model view which is newly created but not yet saved, the app does not push the viewcontroller on top. It actually pushes it on the stack, but behind the current view.
Any idea what's up?
Thanks,
Ken
- (void)tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
articulationAppDelegate *myDelegate=(articulationAppDelegate *)[[UIApplication sharedApplication]delegate];
SCTableViewSection *section = [tableViewModel sectionAtIndex:indexPath.section];
if([section isKindOfClass:[SCArrayOfObjectsSection class]])
{
SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)section;
[objectsSection dispatchSelectRowAtIndexPathEvent:indexPath];
}
if (tableViewModel.tag==1 && indexPath.row==3) {
selectViewController=[[phonemeSelectionViewController_iPhone alloc] init];
selectViewController.delegate=self;
if(clientindex!=-1) {
selectViewController.thisClient=[ourClients objectAtIndex:clientIndex];
} else {
selectViewController.thisClient=myDelegate.tempClient;
}
[selectViewController setTitle:@"Select Phonemes/Cards"];
[selectViewController setNavigationBarType:SCNavigationBarTypeDoneRightCancelLeft];
tempTableViewModel=tableViewModel;
[self.navigationController pushViewController:selectViewController animated:YES];
}
}
#2
Posted 19 September 2011 - 11:02 PM
I haven't studied your code in great detail, but this is obviously causing the issue: Your "if([section isKindOfClass:[SCArrayOfObjectsSection class]])" statement calls dispatchSelectRowAtIndexPathEvent, which pushes an automatically generated detail view, but does not have any "else" statement. What this means is that you're having STV push an auto generated detail view, then at a later time pushing your own detail view simultaneously. You should either have STV push its detail view, or push your own, but not both.
Hope this helps.
#3
Posted 19 September 2011 - 11:36 PM
Thanks for pointing out the issue with the else statement. I fixed that so that the else contains this portion of the code:
if (tableViewModel.tag==1 && indexPath.row==3) {
if (clientIndex != -1) {
myDelegate.tempClient=[ourClients objectAtIndex:clientIndex];
}
selectViewController=[[phonemeSelectionViewController_iPhone alloc] init];
selectViewController.delegate=self;
myDelegate.selectedClientIndex=clientIndex;
if (clientIndex != -1) {
selectViewController.thisClient=[ourClients objectAtIndex:clientIndex];
} else {
myDelegate.tempClient.client_id=-1;
selectViewController.thisClient=myDelegate.tempClient;
}
[selectViewController setTitle:@"Select Phonemes/Cards"];
[selectViewController setNavigationBarType:SCNavigationBarTypeDoneRightCancelLeft];
tempTableViewModel=tableViewModel;
[self.navigationController pushViewController:selectViewController animated:YES];
}
That did not fix the problem. This code was in the tableViewModel didSelectRowAtIndexPath method. The problem arises when I add a new client from the "+" button on the attached screenshot.
I've added the "+" sign to the section with the following code:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
clientsSection.addButtonItem=self.navigationItem.rightBarButtonItem;
#4
Posted 20 September 2011 - 02:11 PM
I have attached a project file which demonstrates the problem.
When editing the client object, clicking on the "Preferred List" table row has the desired effect of opening up the custom view controller.
When creating a new object by hitting the "+" sign and then clicking the "Preferred List", the custom view controller opens, but is behind the current view and causes a crash if the "Done" button is clicked on the custom view controller.
#5
Posted 20 September 2011 - 02:34 PM
Thanks for posting your project, I'll have a look at it and get back to you.
Important: Since this forum is public domain, please make sure you remove all STV files from any future project before posting it here. Thanks!
#6
Posted 20 September 2011 - 03:00 PM
#7
Posted 22 September 2011 - 01:28 PM

I've examined your project: your problem is that you're pushing to the wrong navigation controller in the 'didSelectRowAtIndexPath' method. You should replace:
[self.navigationController pushViewController:selectViewController animated:YES];with:
[tableViewModel.viewController.navigationController pushViewController:selectViewController animated:YES];
Please tell me if you still need any more help.
#8
Posted 22 September 2011 - 04:37 PM
Thanks - that fixed the issue with the view controller showing up behind on the "+" button. But I still have a problem(this is the same for the "+" button or the editing of an existing object.
If I edit the firstname or lastname on the object and then click on the "Preferred List" item it properly shows the custom view controller, but when I return, the edits I put in for the firstname/lastname are lost.
It seems I should be able to preserve those when I implement the - (void)viewControllerDidDisappear:(SCViewController *)viewController cancelButtonTapped:(BOOL)cancelTapped doneButtonTapped:(BOOL)doneTapped method to detect when my custom viewcontroller is finished, but I can't get it to work. This is where I want to update the underlying string value of the "Preferred List" and I was doing it by using [tempTableViewModel reloadBoundValues] where I had stored the calling tableViewModel in tempTableViewModel before pushing the custom view controller. But I lose the other edits at that point which is obviously not good.
Any ideas?
Thanks,
Ken
#9
Posted 23 September 2011 - 06:46 PM
Calling '[tempTableViewModel reloadBoundValues]' is an overkill. You only need to reload the "Preferred List" cell, and hence you should be using something like:
... NSIndexPath *indexPath = [NSIndexPath indexPathForRow:preferredListRow inSection:0]; SCTableViewCell *preferredListCell = [tempTableViewModel cellAtIndexPath:indexPath]; [preferredListCell reloadBoundValue]; ...
Please tell me if you need any more help.
#10
Posted 23 September 2011 - 08:52 PM
Almost. That works great for objects that are in the initial table view. But I need to be able to set the value of the preferredList string in the object that STV uses when it creates a new object from the "+" sign push. I can't figure out a way to get access to that object from - (void)viewControllerDidDisappear:(SCViewController *)viewController cancelButtonTapped:(BOOL)cancelTapped doneButtonTapped:(BOOL)doneTapped.
Thanks,
Ken
#11
Posted 23 September 2011 - 09:21 PM
You can have access to the newly created object by implementing the SCTableViewModelDelegate method called 'itemCreatedForSectionAtIndex'. Hope this helps.
#12
Posted 23 September 2011 - 11:21 PM
#13
Posted 24 September 2011 - 12:09 AM
#14
Posted 24 September 2011 - 12:49 AM
#15
Posted 24 September 2011 - 11:34 AM
Do you see any issues with the code below?
Thanks again so much for your help and patience.
Ken
... - (void)viewControllerDidDisappear:(SCViewController *)viewController cancelButtonTapped:(BOOL)cancelTapped doneButtonTapped:(BOOL)doneTapped { if (doneTapped) { testSTVAppDelegate *myDelegate=(testSTVAppDelegate *)[[UIApplication sharedApplication]delegate]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:3 inSection:0]; SCLabelCell *preferredListCell = [tempTableViewModel cellAtIndexPath:indexPath]; [[tempTableViewModel cellAtIndexPath:indexPath] setBoundValue:myDelegate.myClient.preferredList ]; [preferredListCell reloadBoundValue]; } } ...
#16
Posted 24 September 2011 - 05:13 PM

Your code is fine, except that it's using the 'setBoundValue' setter method of the 'boundValue' property, which should only be used internally by the STV framework (as stated in SCTableViewCell documentation).
The recommended way is to set the value directly to your object:
- (void)viewControllerDidDisappear:(SCViewController *)viewController cancelButtonTapped:(BOOL)cancelTapped doneButtonTapped:(BOOL)doneTapped { if (doneTapped) { testSTVAppDelegate *myDelegate=(testSTVAppDelegate *)[[UIApplication sharedApplication]delegate]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:3 inSection:0]; SCLabelCell *preferredListCell = [tempTableViewModel cellAtIndexPath:indexPath]; [preferredListCell.boundObject setValue:myDelegate.myClient.preferredList forKey:@"preferredListPropertyName"]; [preferredListCell reloadBoundValue]; } }
Hope this helps.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users