0
你好我有此觀點的添加或刪除車中的項目,我想節省的plist項目名稱,說明選擇的數據,並通過用戶點擊結賬所有選定項目後,選擇數量將顯示在下一個屏幕上,我可以這樣做嗎?存儲數據
的TableView委託方法: -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"Cell"];
Product *object = [dataArray objectAtIndex:indexPath.row];
cell.nameLabel.text= object.iD;
cell.descLabel.text=object.desc;
NSString *str = [NSString stringWithFormat:@"%@%@",@"₹",object.price];
cell.priceLabel.text = str;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.addBtn.tag = indexPath.row;
cell.removeBtn.tag = indexPath.row;
cell.count = [NSNumber numberWithInt:j];
cell.quantityLbl.text = [NSString stringWithFormat:@"%@",cell.count];
cell.quantityLbl.layer.cornerRadius =YES;
cell.quantityLbl.layer.borderWidth = 1.0;
return cell;
}
添加按鈕
-(IBAction)addButton:(id)sender
{
CustomTableCell *cell;
UIButton *button3=(UIButton *)sender;
Product *object = [dataArray objectAtIndex:button3.tag];
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
cell = (CustomTableCell*)((UIButton*)sender).superview.superview.superview;
}
else{
cell = (CustomTableCell*)((UIButton*)sender).superview.superview.superview.superview;
}
cell.quantityLbl.text = [NSString stringWithFormat:@"%d",[cell.quantityLbl.text intValue]+1];
i=i+1;
indexLbl.text = [NSString stringWithFormat:@"%@",[NSNumber numberWithInt:i]];
}
在刪除按鈕
-(IBAction)removeButton:(id)sender
{
CustomTableCell *cell;
// check device version
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
cell = (CustomTableCell*)((UIButton*)sender).superview.superview.superview;
}
else{
cell = (CustomTableCell*)((UIButton*)sender).superview.superview.superview.superview;
}
if ([cell.quantityLbl.text intValue] > 0)
{
cell.quantityLbl.text = [NSString stringWithFormat:@"%d",[cell.quantityLbl.text intValue]-1];
i=i-1;
}
indexLbl.text = [NSString stringWithFormat:@"%@",[NSNumber numberWithInt:i]];
}
我知道如何將數據存儲在plist中實際上我想知道如何根據單元格的添加和刪除按鈕來保存數據 – RaviJSS 2015-03-03 11:02:06
@RaviJSS編輯了答案。希望能幫助到你。 – 2015-03-03 11:09:21