介绍
本篇文章给大家分享的是有关怎么在IOS中实现一个购物车界面,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
<强>页面结构强>
@interface CustomButton : UIButton @property (原子,分配)NSInteger indexPathRow; @end
在这个GoodCell里面自定义协议,为了取到某一行的值。
最重要的是选中与没选中的按钮要显示不同的颜色
# pragma mark 作用;selectedBtnAction - (void) selectedBtnAction:(CustomButton *) btn { btn.selected才能=! btn.selected; (才能self.delegate GoodsCellDelegateWithIndexPath btn.indexPathRow):; } - (void) configWithModel:(GoodsModel *)模型{ 时间=self.model 才能;模型; if 才能;(model.btnIsSelected==YES), { ,,,(self.selectedBtn setImage: [UIImage imageNamed: @" sendcar_selected"], forState: UIControlStateNormal); }{其他才能 ,,,(self.selectedBtn setImage: [UIImage imageNamed: @" sendcar_unselected"], forState: UIControlStateNormal); ,,}//才能运单号 时间=self.cardLabel.text 才能;[NSString stringWithFormat: @"运单号:% @", self.model.Ticket_No); }
<>强控制器界面强>
代理协议的实现
# pragma mark 作用;委托 - (void) GoodsCellDelegateWithIndexPath: indexPathRow (NSInteger) { GoodsModel 才能;* cacheModel =, self.dataArr [indexPathRow]; if 才能;(cacheModel.btnIsSelected), {//,,,,NSLog (@"是的==% @" cacheModel.Ticket_No); ,,,cacheModel.btnIsSelected =,没有; ,,},{else //,,,,NSLog (@"没有==% @", cacheModel.Ticket_No); ,,,cacheModel.btnIsSelected =,是的, ,,}//插才能入——删除,,反复切换 (才能self.dataManager insertDataFromModel: cacheModel Ticket_No: cacheModel.Ticket_No); ,,//每次执行插入删除操作就会刷新底部的车辆的按钮 (才能self reloadBottonViewUI); (才能self.tableView reloadRowsAtIndexPaths: @ [[NSIndexPath indexPathForRow: indexPathRow 切开:0]],withRowAnimation: UITableViewRowAnimationNone); }
# pragma mark 作用;刷新底部的选车的数量,reloadBottonViewUI - (void) reloadBottonViewUI { if 才能;([self.dataManager getAllGoodsArrCount)在0),{ ,,,(self.toSelectCarBtn setTitle: [NSString stringWithFormat: @"去发车(% ld)“,(长)[self.dataManager getAllGoodsArrCount]], forState: UIControlStateNormal); }{其他才能 ,,,(self.toSelectCarBtn setTitle: @"去发车“,forState: UIControlStateNormal); ,,} }
去往下个页面需要选中的有数据
# pragma mark 作用;去选车 - (void) toSelectCarBtnAction { if 才能;([self.dataManager getAllGoodsArrCount)在0),{ ,,,//do 一些东西 ,,,(self showSingleAlertViewWith: self 标题:@"提示“,信息:@" do something"]; }{其他才能 ,,,(self showSingleAlertViewWith: self 标题:@"提示“,信息:@"请选择物品“); ,,} }
以上就是怎么在IOS中实现一个购物车界面,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。