Я создал customCell с UIButton
и UILabel
CustomCell значение метки не изменяет
код здесь:
ItemViewController.h:
@interface ItemViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSArray *arr;
IBOutlet ItemCustomCell *itemCell;
}
@property(nonatomic,retain)IBOutlet UITableView *tblItem;
ItemViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
ItemCustomCell *cell = (ItemCustomCell *) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ItemCustomCell" owner:self options:nil];
cell = itemCell;
}
cell.btnPlus.tag=indexPath.row;
[cell.btnPlus addTarget:self action:@selector(incrementValue:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(void)incrementValue:(UIButton *)btnAdd
{
NSLog(@"btn%d",btnAdd.tag);
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:btnAdd.tag inSection:0];
ItemCustomCell *cell = (ItemCustomCell*)[tblItem cellForRowAtIndexPath:indexPath];
cell.lblCount.text=[NSString stringWithFormat:@"%d",[cell.lblCount.text intValue]+1];
}
ItemCustomCell.h
@interface ItemCustomCell : UITableViewCell
{
}
@property(nonatomic,strong)IBOutlet UIButton *btnPlus;
@property(nonatomic,assign)IBOutlet UILabel *lblCount;
Значение по умолчанию метки равно 1. При нажатии на кнопку она показывает следующее значение.
Когда я прокручиваю вверх или вниз значение таблицы tableView сбрасывается на 1. Что я здесь делаю неправильно?
Что такое itemCell? – vikingosegundo
, где вы устанавливаете свой пользовательский элемент lblCount ячейки 1? –
ItemCustomCell.xib – user2681789