创建了一个TableView,然后创建了自定义的单元,其中放了一个Button。现在我想要实现,点击索引的时候获取tableview的索引内容,但是点击了对应索引的按钮之后,没有给出索引列表。
我的tableview类名是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);
}
在**SubMenuCell.h**文件中声明了indexPath