UA-17470720-3

Jump to content


Photo
- - - - -

SCTableViewModel New vs Existing Objects


  • Please log in to reply
15 replies to this topic

#1 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 17 September 2011 - 11:37 AM

I have the following code in my app. All works well on existing client objects. The code below senses which row of the STV was selected. If it was row three then I push a custom viewcontroller which does not use tables, but inherits from SCViewController.

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 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 September 2011 - 11:02 PM

Hi Ken,

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 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 19 September 2011 - 11:36 PM

Tarek,
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 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 20 September 2011 - 02:11 PM

Tarek,

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 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 20 September 2011 - 02:34 PM

Hi Ken,

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 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 20 September 2011 - 03:00 PM

Sorry about the the STV source files - I wasn't thinking - won't happen again.

#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 22 September 2011 - 01:28 PM

No problem Ken :)

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 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 22 September 2011 - 04:37 PM

Tarek,
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 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 23 September 2011 - 06:46 PM

Hi Ken,

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 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 23 September 2011 - 08:52 PM

Tarek,

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 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 23 September 2011 - 09:21 PM

Hi Ken,

You can have access to the newly created object by implementing the SCTableViewModelDelegate method called 'itemCreatedForSectionAtIndex'. Hope this helps.

#12 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 23 September 2011 - 11:21 PM

That's one I actually tried. That event is fired as soon as the "+" button is tapped and thus too early in the process.. I need access to the object after the "Done" button on the custom viewcontroller is finished. Because on existing objects I know which one was accessed, I can update the underlying data prior to calling [preferredListCell reloadBoundValue] and all works well. However on objects created by STV I need to be able to update the preferredList string after the custom viewcontroller is finished because that is what will modify the string value - so I need access as soon as the "Done" button is tapped. I'm assuming if I update the underlying object then the call to [preferredListCell reloadBoundValue] will succeed for the newly created object.

#13 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 24 September 2011 - 12:09 AM

Oh then you'll need to implement 'itemAddedForSectionAtIndexPath' instead. This method gets called as soon as the 'Done' button is tapped and the object is added to the items array. Please tell me if that's what you're looking for.

#14 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 24 September 2011 - 12:49 AM

I had tried that as well. That gets fired when the "Done" button is tapped on the STV created view and that is too late in the process. I need access to the object after the "Done" is tapped on my custom viewcontroller. The only way I've been able to interact at that point is with - (void)viewControllerDidDisappear:(SCViewController *)viewController cancelButtonTapped:(BOOL)cancelTapped doneButtonTapped:(BOOL)doneTapped. It's at that point that I need to update the underlying object newed up by STV so that when I call [preferredListCell reloadBoundValue] it properly displays the string modified by the custom viewcontroller.

#15 Ken Walker

Ken Walker

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 38 posts
Reputation: 2
Good

Posted 24 September 2011 - 11:34 AM

I think I've gotten where I need to be. Wanted to see if you see any issues with my solution. The key was calling the setBoundValue to my desired value before calling [preferredListCell reloadBoundValue]. This appears to work for both existing and newly created objects. I've implemented it in my actual project in which the custom view controller is much more complicated, but still just manipulates a string.

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 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 24 September 2011 - 05:13 PM

You're most welcome Ken :)

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