UA-17470720-3

Jump to content


Photo
- - - - -

How to add a cell in my existing tableview?

models sections cells web-services

  • Please log in to reply
4 replies to this topic

#1 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 06 February 2013 - 06:29 PM

Hi,

I could not find a way to add a cell in my tableview while using SCArrayOfObjectsModel, I am trying to achieve One-to-One relations between two Parse.com classe. Help me to achieve the same.

Please give some code syntax.

Thanks,
bala.

Edited by Balachandhar, 06 February 2013 - 06:30 PM.


#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 06 February 2013 - 09:09 PM

Hi Bala,

What kind of custom cell are you trying to add? In general, SCArrayOfObjectsModel automatically generates all its items, but you could manually insert additional cells using the 'didFetchItemsFromStore' section action. For example, here is how to add an additional button cell:

sectionActions.didFetchItemsFromStore = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items)
{
  // Add a button cell at the end of the items list
  SCTableViewCell *buttonCell = [SCTableViewCell cellWithText:@"Tap me!" textAlignment:NSTextAlignmentCenter];
  buttonCell.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
  {
     NSLog(@"buttonCell tapped!");
  };

  [items addObject:buttonCell];
};


#3 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 07 February 2013 - 09:00 AM

Hi Tarek,

I want to add a selection cell in my tableview generated by SCArrayOfObjectsModel, e.g.: In my case, I am tying to add a selection cell called "Phone number", i have a class named 'ContactPhone' in parse.com. So, I am trying to fetch and load the list of phone numbers from parse.com class('ContactPhone') for my custom Selectioncell("Phone number"). So that user can tap the selection cell and pick a phone number they want.


SCParseComDefinition *contactphonedef = [SCParseComDefinition definitionWithClassName:@"ContactPhone" columnNamesString:@"label;phone;" applicationId:applicationId restAPIKey:restAPIKey];
[contactphonedef propertyDefinitionWithName:@"contactId"];


SCParseComDefinition *taskDef = [SCParseComDefinition definitionWithClassName:@"Contact" columnNamesString:@"firstName;prefix;lastName;notes;title;companyCheck;contactId;" applicationId:applicationId restAPIKey:restAPIKey];
[taskDef propertyDefinitionWithName:@"contactId"].type=SCPropertyTypeNone;

[taskDef propertyDefinitionWithName:@"prefix"].required=TRUE;
[taskDef propertyDefinitionWithName:@"firstName"].required=TRUE;
[taskDef propertyDefinitionWithName:@"lastName"].required=TRUE;
SCPropertyDefinition *descPDef = [taskDef propertyDefinitionWithName:@"notes"];
descPDef.type = SCPropertyTypeTextView;
SCPropertyDefinition *companyCheckPDef = [taskDef propertyDefinitionWithName:@"companyCheck"];
companyCheckPDef.type = SCPropertyTypeSwitch;
SCWebServiceStore *webStore = [SCWebServiceStore storeWithDefaultWebServiceDefinition:taskDef];
SCArrayOfObjectsModel *webModel = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView dataStore:webStore];


webModel.dataFetchOptions = [SCWebServiceFetchOptions options];
webModel.addButtonItem = self.navigationItem.rightBarButtonItem;
webModel.searchBar = searchBar;
//search by both first and last names
webModel.searchPropertyName = @"firstName;lastName";
webModel.autoSortSections = 0;
// webModel.autoGenerateSectionIndexTitles = TRUE;
webModel.sectionIndexTitles = [NSArray arrayWithObjects:
@"{search}", @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L",@"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"#", nil];


webModel.sectionActions.didFetchItemsFromStore = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items)
{
// Add a button cell at the end of the items list
SCSelectionCell *buttonCell = [SCSelectionCell cellWithText:@"Phone numbers" textAlignment:NSTextAlignmentCenter];
buttonCell.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
NSLog(@"buttonCell tapped!");
};

[items addObject:buttonCell];
};


webModel.modelActions.didFetchItemsFromStore = ^(SCArrayOfItemsModel *itemsModel, NSMutableArray *items)
{
// Add a button cell at the end of the fetched items list
SCSelectionCell *buttonCell = [SCSelectionCell cellWithText:@"Phone numbers" textAlignment:NSTextAlignmentCenter];
buttonCell.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
NSLog(@"buttonCell tapped!");
};

[items addObject:buttonCell];
};


webModel.dataFetchOptions.sort = 0; // Sort names
webModel.detailViewControllerOptions.navigationBarType = SCNavigationBarTypeDoneRightCancelLeft;

self.tableViewModel = webModel;
---------------------------------------

Also webModel.sectionActions.didFetchItemsFromStore/webModel.modelActions.didFetchItemsFromStore both methods are not called.

Edited by Balachandhar, 07 February 2013 - 09:02 AM.


#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 07 February 2013 - 11:06 AM

Hi Bala,

Since you're using an SCArrayOfObjectsModel, you should only use 'modelActions.didFetchItemsFromStore' and completely remove 'sectionActions.didFetchItemsFromStore'.

This however is not the reason it's not being called. I believe we fixed a bug in 3.1.7 where 'didFetchItemsFromStore' is not properly fired when SCArrayOfObjectsModel is bound to a web service. We should be releasing 3.1.7 by next Mon, so please let me know if it fixes this for you. Thanks!

#5 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 07 February 2013 - 07:42 PM

Hi Tarek,

If it fixed, how can i do the one-to-one relation mapping here? help me, i am tiered to searching the way/method to do it.

thanks,
bala.





Also tagged with one or more of these keywords: models, sections, cells, web-services

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users