2012-12-25 101 views
0

創建表格視圖。 然後創建一個自定義表格查看單元格並在單元格上放置一個按鈕,現在我嘗試在單擊索引時獲取表格視圖索引。 但是,當我點擊單元格上的按鈕它沒有給我列表的索引。如何在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

回答

0

您的NSLog有問題;試試這個(改變%和@順序)。

- (IBAction)addItemIntoOrder:(id)sender 
{ 
    NSLog(@"%@",indexPath); 
    NSLog(@"%@",indexPath.row); 
} 
0

確保addItemIntoOrder:動作在IB正確掛接到您的委託。

相關問題