метод вызова из пользовательской ячейки в приложении iphone

у меня есть один контроллер представления
Имя : FirstVC

у меня есть представление таблицы в этом контроллере представления. в представлении таблицы я загружаю пользовательскую ячейку. в моей пользовательской ячейке есть 1 ярлык и 1 кнопка. Я установил метку, а также кнопку пользовательской ячейки из FirstVC. См. приведенный ниже код.

в FirstVC.h

@interface FirstVC : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
    IBOutlet UITableView *TblView;
    IBOutlet CustomCell *customCell;
}
- (void)addCounter:(NSInteger)pCat_ID;

@end

в FirstVC.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *cellIdentifier = @"Cell";
        CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if(cell == nil){
        [[NSBundle mainBundle] loadNibNamed:@"CustomCell_iPhone" owner:self options:nil];
            cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            cell = categoryCustomCell;
        }
NSInteger pCat_id = [[[arrayCategoryData objectAtIndex:indexPath.row] objectForKey:@"cat_id"] integerValue];
        [customCell setTextForLable:@"Test"];
        [customCell setAddCounterButton:pCat_id];

        return cell;
}

- (void)addCounter:(NSInteger)pCat_ID
{
    //Some code here….
}

в CustomCell.h

@interface CustomCell : UITableViewCell
{
    IBOutlet UILabel *lblCategoryName;
    IBOutlet UIButton *btnAddCounter;
}

- (void)setTextForLable:(NSString *)cat_name;
- (void)setAddCounterButton:(NSInteger)cat_ID;

@end

в CustomCell.m

@implementation CustomCell

- (void)setTextForLable:(NSString *)cat_name
{
    lblCategoryName.text = cat_name;
}

- (void)setAddCounterButton:(NSInteger)cat_ID
{
    [btnAddCounter addTarget:self action:@selector(addCounter:cat_ID) forControlEvents:UIControlEventTouchUpInside];
}

@end

я хочу вызвать метод addCounter:(NSInteger)pCat_ID из пользовательской ячейки. но эта идея может не сработать. Пожалуйста, предложите мне новую идею.


person Bhavin_m    schedule 03.11.2012    source источник
comment
Какая польза от cat_ID? и как он рассчитывается?   -  person Rushi    schedule 03.11.2012


Ответы (1)


person    schedule
comment
Правильно, по моему мнению, просто передайте индексный путь в селекторе, чтобы вы могли получить строку, на которой была нажата кнопка. - person amar; 03.11.2012