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