Welcome, Guest
Username Password: Remember me

Accessing boundObject from SCArrayOfObjectsModel
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Accessing boundObject from SCArrayOfObjectsModel

Accessing boundObject from SCArrayOfObjectsModel 1 year, 6 months ago #1

Hi,

In my didSelectRowAtIndexPath method, I'm trying to access the boundObject of a cell which was generated with SCArrayOfObjectsModel:

- (void)viewDidLoad {
[super viewDidLoad];
 
NSArray *properties = [NSArray arrayWithObjects:@"name", nil];
 
SCClassDefinition *classDef = [[SCClassDefinition alloc] initWithClass:[STIMerchant class] withPropertyNames:properties];
 
SCArrayOfObjectsModel *model = [[SCArrayOfObjectsModel alloc] initWithTableView:self.aTableView withViewController:self withItems:nil withClassDefinition:classDef];
model.allowEditDetailView = NO;
 
self.tableModel = model;
[model release];
 
self.tableModel.autoSortSections = YES;
self.tableModel.autoGenerateSectionIndexTitles = YES;
 
[self.webServices fetchStoreDirectory];
 
}

- (void) tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 
// looking at cell.bouncObject here gives back nil.
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
 
STIMerchant *merchant = (STIMerchant *)[self.merchants objectAtIndex:[self arrayIndexFromIndexPath:indexPath]];
 
if (merchant) {
MerchantStoreViewController *viewController = [[MerchantStoreViewController alloc] init];
viewController.merchant = merchant;
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
}
 



I thought that I would be able to ask the cell for its boundObject. But it always comes back nil. So to get around that, I wrote a method to find the index into my array given the current IndexPath.

here's the method I use for that:
- (NSInteger)arrayIndexFromIndexPath:(NSIndexPath *)indexPath {
NSInteger arrayIndex = 0;
if (indexPath.section == 0) {
arrayIndex = indexPath.row;
} else {
for (int i = 0; i < indexPath.section; i++) {
arrayIndex += [self.aTableView numberOfRowsInSection:i];
}
arrayIndex += indexPath.row;
}
 
return arrayIndex;
}


It works, but it would be nice to be able to have access to the boundObject of a cell directly.

Am I missing something here? Is there an easier way?

Thanks,

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Accessing boundObject from SCArrayOfObjectsModel 1 year, 6 months ago #2

Hi Brendan,

This post has the answer to your question: www.sensiblecocoa.com/forum/sensible-tab...displaycell.html#502

To us this design decision was more a matter of philosophy, as the cell itself is actually not bound to anything, but rather its detail section is what's bound to the object. Having said that, we will definitely look into this again from a usability point of view.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Accessing boundObject from SCArrayOfObjectsModel 1 year, 6 months ago #3

That worked perfect!

Thanks!

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Accessing boundObject from SCArrayOfObjectsModel 10 months, 3 weeks ago #4

Hi Brendan, long time!

Relating to our above discussion, I just wanted to update you that in STV 2.1 (www.sensiblecocoa.com/forum/announcement...1-beta-released.html) SCArrayOfObjectsSection cells now have their boundObject property pointing to the object they represent.

Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Accessing boundObject from SCArrayOfObjectsModel 10 months, 3 weeks ago #5

Hey Tarek!

Yes, it's been a long time since I chimed in here. Thanks for adding this feature! It'll make my code much simpler!

Thanks for doing such a great job on STV!

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com
  • Page:
  • 1
Time to create page: 1.73 seconds