創建表格視圖。 然後創建一個自定義表格查看單元格並在單元格上放置一個按鈕,現在我嘗試在單擊索引時獲取表格視圖索引。 但是,當我點擊單元格上的按鈕它沒有給我列表的索引。如何在iPhone中單擊自定義列表單元格按鈕時添加動作事件工作
我的表視圖類名SubMenuViewController
和細胞的類名是SubMenuCell
和我的SubMenuViewController
代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ModelLocator *model = [ModelLocator getInstance];
static NSString *simpleTableIdentifier = @"SubMenuCell";
SubMenuCell *cell = (SubMenuCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SubMenuCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if (model.foodSubItemList) {
FoodSubItemVO* foodSubItemTemp = [model.foodSubItemList objectAtIndex:indexPath.row];
[cell.lbSubFoodItem setText: foodSubItemTemp.foodSubItemName];
[cell.lbPrice setText: foodSubItemTemp.price];
[cell setIndexPath:indexPath];
}
return cell;
}
,在這裏我SubMenuCell代碼
- (IBAction)addItemIntoOrder:(id)sender {
NSLog(@"@%",indexPath);
NSLog(@"@%",indexPath.row);
}
indexPath申報SubMenuCell.h