ios仿收货地址管理

最近公司项目增加了一个需求,然后要有收货地址的管理,有单选框的设置,我昨晚也是写了很晚才写出来的,然偶今天就分享一下吧,同时也是我自己积累的过程,当然了,我今天给的是一个demo的例子,我不可能把自己的项目搬进来。下面就不说废话了,直接上代码。

我现在写的是一个简单的demo,至于后面可能会加上难的吧,然后我也会更新的。

#import "ViewController.h"

 

#define rowCount        5

 

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

 

@property(nonatomic,strong)NSMutableArray *allButtonArray;

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    self.allButtonArray = [[NSMutableArray alloc] init];

    

    UITableView *tabView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

    tabView.delegate =self;

    tabView.dataSource =self;

    

    [self.view addSubview:tabView];

    

}

 

 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}

 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return rowCount;

    

}

- (UITableViewCell *)tableView:(UITableView *)view cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *identifier = @"identifier";

    

    UITableViewCell *cell = (UITableViewCell*)[view  dequeueReusableCellWithIdentifier:identifier];

    

    if (cell==nil) {

        

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.textLabel.text = @"aaa";

        

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

        button.tag = 1000+indexPath.row;

        [button setImage:[UIImage imageNamed:@"unselect"] forState:UIControlStateNormal];

//        [button setTitle:@"title" forState:UIControlStateNormal];

        button.frame = CGRectMake(0, 0, 200, 60);

        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];

        

        [cell addSubview:button];

        

        [_allButtonArray addObject:button];

    }

    

    return cell;

}

 

- (void)buttonClick:(UIButton *)button

{

    NSLog(@"click-----------");

    [button setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];

//    [button setTitle:@"afterClick" forState:UIControlStateNormal];

    

//    for ( int i=0; i<rowCount; i++) {

//        NSInteger tag = 1000+i;

//        if (tag!=button.tag) {

//            UIButton *unselectedbutton = (UIButton *)[self.view viewWithTag:tag];

//            [unselectedbutton setImage:[UIImage imageNamed:@"unselect"] forState:UIControlStateNormal];

//        }

//    }

    

    for (int i=0; i<[_allButtonArray count]; i++) {

        UIButton *cellButton = (UIButton *)_allButtonArray[i];

        if (cellButton!=button) {

            [cellButton setImage:[UIImage imageNamed:@"unselect"] forState:UIControlStateNormal];

        }

    }

   

}

 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"...........");

 

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

 

@end

 

转载于:https://www.cnblogs.com/huiyi-520/p/7500673.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值