Я разработал собственную ячейку таблицы.который отображает информацию о продукте.
Когда я реализую CellForRowAtIndexPath, я делаю это.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *sectionTableCellIdentifier = [[NSString alloc] initWithFormat:@"GLItemTableCellIdentifierNumber%d",indexPath.section];
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GLItemDetailsTableCellIdentifier"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sectionTableCellIdentifier];
if (cell == nil)
{
NSDictionary *dict = [self.listData objectAtIndex:indexPath.row];
ItemsListTableCell *cell = (ItemsListTableCell *)[tableView dequeueReusableCellWithIdentifier:sectionTableCellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ItemsListTableCell"
owner:self options:nil];
for (id oneObject in nib)
{
if ([oneObject isKindOfClass:[ItemsListTableCell class]])
{
cell = (ItemsListTableCell *)oneObject;
}
}
NSString *priceinfo = [[NSString alloc] initWithFormat:@"$%@",[dict objectForKey:@"CurrentPrice"]];
NSString *sizeinfo = [[NSString alloc] initWithFormat:@"Size: %@",[dict objectForKey:@"Size"]];
NSString *upcInfo = [[NSString alloc] initWithFormat:@"UPC: %@",[dict objectForKey:@"ID"]];
NSString *strQuantity = [[NSString alloc] initWithFormat:@"%@",[dict objectForKey:@"Quantity"]];
cell.lblProductName.text = [dict objectForKey:@"Name"];
cell.lblSize.text = sizeinfo;
cell.lblBrand.text = [dict objectForKey:@"BrandName"];
cell.lblProductCode.text = upcInfo;
cell.lblQuantity.text = strQuantity;
cell.lblPrice.text = priceinfo;
cell.lblStoreName.text = [dict objectForKey:@"StoreName"];
cell.isSelected = NO;
[cell.btnSelected addTarget:self action:@selector(cellButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[upcInfo release];
[priceinfo release];
[strQuantity release];
[sizeinfo release];
return cell;
}
return cell;
}
сейчас для события щелчка я делаю
- (IBAction)cellButtonTapped:(id)sender
{
UIView *contentView = [sender superview];
ItemsListTableCell *cell = (ItemsListTableCell *)[contentView superview];
NSIndexPath *indexPath = [table indexPathForCell:cell];
NSUInteger buttonRow = [[self.table
indexPathForCell:cell] row];
NSUInteger buttonSection = [[self.table
indexPathForCell:cell] section];
NSLog(@"Index Path Row : %d",buttonRow);
NSLog(@"Index Path Section : %d",buttonSection);
ItemsListTableCell *buttonCell =
(ItemsListTableCell *)[table cellForRowAtIndexPath:indexPath];
if (buttonCell.isSelected == YES)
{
buttonCell.isSelected = NO;
UIImage *image = [[UIImage imageNamed:@"checkbox-empty.png"] autorelease];
[buttonCell.btnSelected setImage:image forState:UIControlStateNormal];
}
else
{
buttonCell.isSelected = YES;
UIImage *image = [[UIImage imageNamed:@"checkbox-full.png"] autorelease];
[buttonCell.btnSelected setImage:image forState:UIControlStateNormal];
}
self.txtQuantity.text = buttonCell.lblQuantity.text;
NSString *buttonTitle = buttonCell.lblProductName.text;
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"You tapped the button"
message:[NSString stringWithFormat:
@"You tapped the button for %@", buttonTitle]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
Проблема заключается в том, когдая нажимаю на кнопку проверки, это идет на событие.но я не могу определить, что такое родительская ячейка.так как в ячейке есть некоторые значения.