UA-17470720-3

Jump to content


Photo
- - - - -

SCClassDefinition Examples


  • Please log in to reply
11 replies to this topic

#1 Bradley Van Dyk

Bradley Van Dyk

    Sr. Member

  • STV 2.0
  • PipPipPip
  • 35 posts
Reputation: 2
Good

Posted 08 September 2011 - 06:06 PM

Are there any more SCClassDefinition examples? I'm having a very hard time customizing this. I'm able to get very simple views with the video tutorial, but I'd like to do more including the following:

1. Customize the "Done" button on Class views. I want to do some validation before I save items
2. Edit the onclick event for each of the items added. I want to be able to show a custom view when they click on the item. If they want to edit the information, then the user must click edit first.

Please let me know if this is possible but so far I've only been able to do simple things with this great tool.

Thanks.

#2 Bradley Van Dyk

Bradley Van Dyk

    Sr. Member

  • STV 2.0
  • PipPipPip
  • 35 posts
Reputation: 2
Good

Posted 08 September 2011 - 06:15 PM

I almost figured out how to do 2. by using SCTableViewModelDelegate and overriding - (void)tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath

However, the problem with that is I can push my own ViewController when self.editing = NO, but I don't know how to push the normal ViewController generated by the SCTableViewModel otherwise. Not sure.

#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 08 September 2011 - 06:33 PM

Hi Bradley,

1. Please tell me if that's the same question as the one answered here: http://www.sensiblec...ector.html#4011

#4 Bradley Van Dyk

Bradley Van Dyk

    Sr. Member

  • STV 2.0
  • PipPipPip
  • 35 posts
Reputation: 2
Good

Posted 08 September 2011 - 06:53 PM

I think I made more progress by doing this:

if (self.isEditing) {
SCTableViewSection *section = [tableViewModel sectionAtIndex:indexPath.section];
if ([section isKindOfClass:[SCArrayOfObjectsSection class]])
{
SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)section;
[objectsSection dispatchSelectRowAtIndexPathEvent:indexPath];
}
}

However, is there a way to do something like this:
[tableViewModel getDetailTableViewModel:indexPath]?

Sorry for my sporadic thoughts. Would appreciate any help.

#5 Bradley Van Dyk

Bradley Van Dyk

    Sr. Member

  • STV 2.0
  • PipPipPip
  • 35 posts
Reputation: 2
Good

Posted 08 September 2011 - 06:56 PM

Hi Bradley,

1. Please tell me if that's the same question as the one answered here: http://www.sensiblec...ector.html#4011


Yes, sorry =(

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 08 September 2011 - 07:12 PM

is there a way to do something like this:
[tableViewModel getDetailTableViewModel:indexPath]?


Sure, just implement the SCTableViewModelDelegate method called tableViewModel:detailViewWillAppearForRowAtIndexPath:withDetailTableViewModel:.

Hope this helps.

#7 Bradley Van Dyk

Bradley Van Dyk

    Sr. Member

  • STV 2.0
  • PipPipPip
  • 35 posts
Reputation: 2
Good

Posted 08 September 2011 - 07:19 PM

First of all, thanks for your help and great documentation so far. I'm still learning but I've been trying to document my status as I progress and here's where I'm at...

1. Yes this was a duplicate and the Validation video isn't perfect, but it's close. What I'd like to do is custom validation that can be more user interactive. For example, if they enter in a URL, I want to make an HTTP request to check the URL to ensure it's valid. If not, display a message to the user and don't allow them to save. I think I'm close with what I have below.

2. I think I'm close here as well.

- (void)tableViewModel:(SCTableViewModel *)tableViewModell didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
		SCTableViewSection *section = [tableViewModel sectionAtIndex:indexPath.section];
		if ([section isKindOfClass:[SCArrayOfObjectsSection class]])
		{
			SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)section;
			Account *acc = [[objectsSection items] objectAtIndex:indexPath.row];
			NSLog(@"%@", acc.name);
			
			
			if (self.isEditing) {
				[objectsSection dispatchSelectRowAtIndexPathEvent:indexPath];
//				objectsSection.
			}
			else {
				DetailsViewController *con = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
				[self.navigationController pushViewController:con animated:YES];
				[con release];
			}
		}

		
		return;
}

and

- (void)tableViewModel:(SCTableViewModel *) tableViewModel detailViewWillAppearForRowAtIndexPath:(NSIndexPath *) indexPath withDetailTableViewModel:(SCTableViewModel *) detailTableViewModel {
	UIViewController * uiv = detailTableViewModel.viewController;
	uiv.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:@selector(doneClicked)] autorelease];
}


I think this solution will work, but I'm not sure if it's correct or the most elegant. Would appreciate any direction. Thanks again!

#8 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 08 September 2011 - 09:03 PM

You're most welcome Bradley!

1. In addition to the validation mechanisms we discussed earlier, STV can also notify you whenever the value of any cell changes and have you take appropriate action. To get notified, just implement the SCTableViewModelDelegate method called 'valueChangedForRowAtIndexPath'. As always, please tell me if you need any more help here.

2.
a. Your implementation of 'didSelectRowAtIndexPath' is perfectly written! I am just wondering why you need to push a custom detail view. I am asking because STV may also provide help here.

b. In your implementation of 'detailViewWillAppearForRowAtIndexPath', I am really not sure why you're overriding STV's 'Done' button with your own. This may very well break the saving mechanism.

#9 Bradley Van Dyk

Bradley Van Dyk

    Sr. Member

  • STV 2.0
  • PipPipPip
  • 35 posts
Reputation: 2
Good

Posted 08 September 2011 - 09:21 PM

Allow me to explain in more detail...

1. Well what we want to do is have 3 SCTableTextFieldCells - username, password, and host. After they're finished, we'd like to use those values and test them against our server to see if they're valid. If so, then allow them to save the new account, otherwise they must edit the information so we need to wait until the user presses "done". Do you think this can be done?

2. As I mentioned above, we basically want a list of accounts. When the user clicks an account, it will show information from our server based on the information input in step 1. However, if the user needs to change his/her password, then he/she can click edit and then click the table again, showing again the view in step 1.

Again, I've already learned a lot but I may be over complicating this. Please let me know your thoughts and thanks for your help, so far this product has been great to use :)

#10 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 08 September 2011 - 10:33 PM

1.Do you need to do the server side check as soon as the data is entered then enable the 'Done' button, or do you want to do it after the 'Done' button has been tapped?

2. Ok, got it. Thanks!

#11 Bradley Van Dyk

Bradley Van Dyk

    Sr. Member

  • STV 2.0
  • PipPipPip
  • 35 posts
Reputation: 2
Good

Posted 08 September 2011 - 11:58 PM

1. After the done button has been tapped so the user can be sure the information is correct.

2. Since I'm trying to learn, I'd like to get your feedback. Other than the validation, was my implementation of the Delegate / TableViewModel correct to distinguish a difference between ViewDetails and EditSettings?

#12 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 09 September 2011 - 12:37 AM

1. There is a delegate method called 'tableViewModel:itemAddedForSectionAtIndexPath:item:' that gets called right after the Done button is tapped. Once this method gets called though, the data has already been saved and added, so I am not sure if you want to delete the data if it's invalid? Here is what I suggest you should do and what I think is best practice:

a. Add a fourth cell to your cells that will act as a button that the user should tap to validate the values server side. This cell can be a simple [SCTableViewCell cellWithText:@"Validate Data"] that you can add to the existing detail section in 'detailViewWillAppearForSectionAtIndex'.

b. Have the Done button disabled until the cell is tapped and the user correctly authenticated. This way when Done is tapped you don't need any more checks.


2. An alternative idea idea to what you did would be to use the same idea I stated above, but in a different context. All you need to do is rename the fourth cell if the root table view is in editing mode to say @"Change Password", and do a password change operation when the cell is tapped. I think this might be more intuitive to the user.


Please tell me if you need any help with coding the above.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users