Welcome, Guest
Username Password: Remember me

Another custom cell question
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Another custom cell question

Another custom cell question 1 year, 1 month ago #1

Hi tarekskr,

I think i am missing something here. I have a "normal" cell that once touched it loads a new SCT page. that works fine.

In order to changed to a custom cell i changed this in my .h file (i think that is correct?):
SCTableViewModelDelegate

to
SCTableViewModelDataSource


I have coded the custom cell like this:
- (SCControlCell *)tableViewModel:(SCTableViewModel *)tableViewModel customCellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create & return a custom cell based on the cell in ContactOverviewCell.xib
NSDictionary *contactOverviewBindings = [NSDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:@"time",@"description",@"location", nil]
forKeys:[NSArray arrayWithObjects:@"1",@"2",@"3", nil]]; // 1,2,3 are the control tags
SCControlCell *contactOverviewCell = [SCControlCell cellWithText:nil withBoundObject:nil withObjectBindings:contactOverviewBindings
withNibName:@"CustomCell"];
 
return contactOverviewCell;
}
 


This all works fine.

However, now when i touch a row it will not process didSelectRowAtIndexPath function. It does nothing.
-(void)tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
 
// define the target view controller
HCAViewController *view = [[HCAViewController alloc] initWithNibName:@"HCAViewController" bundle:nil];
 
view.flight = cell.textLabel.text;
 
// set target view controller title
view.navigationItem.title = cell.textLabel.text;
 
// push target view onto nav controller
[[self navigationController] pushViewController:view animated:YES];
[view release];
 
}


So how do i?

1. load the next SCT page when row selected?

2. When row selected in a custom cell how can i get access to the cell data so i can pass it to the next SCT page: For example:
view.location = cell.location.text;

Re: Another custom cell question 1 year, 1 month ago #2

Hi Trav,

You need to conform to both protocols:

 
...
@interface MyViewController : UITableViewController <SCTableViewModelDataSource, SCTableViewModelDelegate>
...
 


Hope this helps.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
Last Edit: 1 year, 1 month ago by tarekskr.

Re: Another custom cell question 1 year, 1 month ago #3

Worked perfectly! Your support is awesome!!! Best i have ever had! Thanks.

Oh one more question, now that my custom cell is working. how can i get access to the custom cell data so that i can pass?

I can't do it this way anymore:
cell.textLabel.text


Thanks again for your fast replies.
The following user(s) said Thank You: tarekskr

Re: Another custom cell question 1 year, 1 month ago #4

Thanks for all the complements Trav

I am not sure I fully understand your question. Would you please elaborate? Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Another custom cell question 1 year, 1 month ago #5

sure.

when i select a row from a custom cell using this code:
-(void)tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
 
NSLog(@"tableModel.activeCell = %@", tableModel.activeCell);
 
// define the target view controller
HCAViewController *view = [[HCAViewController alloc] initWithNibName:@"HCAViewController" bundle:nil];
 
view.location = cell.location.textLabel.text; <----- How can i get location text
 
// set target view controller title
view.navigationItem.title = cell.textLabel.text;
 
// push target view onto nav controller
[[self navigationController] pushViewController:view animated:YES];
[view release];
 
}

I need to pass one of the cell text (or get access to the core data for that row) to the next view controller to filter its data.

So for a quick example:

View 1: lists a SCT with custom cell containing countries of the world and there population count
Action 1: Click on Austraila
Code 1: need to get the cell text for the country name
View 2. filter states based on country 'Australia'

The only missing piece for me is the "Code 1" in the above example. Do i use controlTag number to access it somehow?

I hope this a little clearer.

Cheers,
Trav.

Re: Another custom cell question 1 year, 1 month ago #6

Thanks, I now get what you mean. There are at least three ways to do that from within the didSelectRowAtIndexPath method:

1- Get the managed object bound to the cell

 
...
SCArrayOfObjectsSection *objectsSection =
(SCArrayOfObjectsSection *)[tableViewModel sectionAtIndex:0];
 
// Get the corresponding managed object
NSManagedObject *object = (NSManagedObject *)[objectsSection.items objectAtIndex:indexPath.row];
 
// Get the attribute of interest
NSString *location = (NSString *)[object valueForKey:@"location"];
...
 


The next two options assume that you have a UITextField with tag=3 on the custom cell

2- Have the custom cell retrieve the location data for you

 
...
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
NSString *location = nil;
if([cell isKindOfClass:[SCControlCell class]])
{
SCControlCell *customCell = (SCControlCell *)cell;
location = (NSString *)[customCell boundValueForControlWithTag:3];
}
...
 


3- Get the control on the custom cell and retrieve the data yourself

 
...
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
NSString *location = nil;
if([cell isKindOfClass:[SCControlCell class]])
{
SCControlCell *customCell = (SCControlCell *)cell;
UITextField *locationField = (UITextField *)[customCell controlWithTag:3];
location = locationField.text;
}
...
 


You should choose the most convenient method to you depending on your own situation. Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 2.10 seconds