我正在开发一个购物应用程序,其中正在实现一个购物车。在我的应用中,单击加号按钮时需要增加产品数量,单击减号按钮时需要减少产品数量。这是我的问题,当我单击加号按钮时,tableviewcell中的所有文本字段值都在更改。帮帮我,下面是加号按钮的操作方法
-(IBAction)plusBtn:(UIButton*)plus
{
[self.tbleView beginUpdates];
UITableViewCell *clickedCell = (UITableViewCell *)[[plus superview] superview];
NSIndexPath *clickedButtonIndexPath = [self.tbleView indexPathForCell:clickedCell];
plus.tag = clickedButtonIndexPath.row;
quantity.tag = clickedButtonIndexPath.row;
_curr =_curr+1;
quantity.text = [NSString stringWithFormat:@"%d",_curr];
[self.tbleView endUpdates];
[self.tbleView reloadData];
}
像这样
得到..
您可以检查此功能吗?这将对您有用。我希望它。
- (void)viewDidLoad
{
[super viewDidLoad];
quantity =[NSMutableArray new];
occu_list = [[NSArray alloc] initWithObjects:@"Occupation", @"two", @"three", @"four", @"five", @"six", @"seven", @"eight", nil];
for(int i=0;i<[occu_list count];i++)
{
[quantity addObject:@"0"];
}
click_textView=[[UIView alloc]init];
click_textView.frame=self.view.frame;
[self.view addSubview:click_textView];
[self tableviewone];
}
-(void)tableviewone
{
tbl_view = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
tbl_view.delegate = self;
tbl_view.dataSource = self;
tbl_view.backgroundColor = [UIColor whiteColor];
tbl_view.layer.borderColor=[[UIColor orangeColor]CGColor];
tbl_view.layer.borderWidth=2.0f;
tbl_view.layer.cornerRadius=5.0f;
tbl_view.layer.masksToBounds=YES;
[click_textView addSubview:tbl_view];
}
-(IBAction)check_btn_action:(id)sender
{
UIButton *btntag=(UIButton*)sender;
NSLog(@"%li",(long)btntag.tag);
NSLog(@"%@",[quantity objectAtIndex:btntag.tag]);
int ad=[[quantity objectAtIndex:btntag.tag]integerValue];
ad=ad+1;
[quantity removeObjectAtIndex:btntag.tag];
[quantity insertObject:[NSString stringWithFormat:@"%i",ad] atIndex:btntag.tag];
[tbl_view reloadData];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句