ios仿收貨地址管理

來源:互聯網
上載者:User

標籤:oid   nonatomic   state   bsp   ==   tableview   title   source   nta   

最近公司項目增加了一個需求,然後要有收貨地址的管理,有單選框的設定,我昨晚也是寫了很晚才寫出來的,然偶今天就分享一下吧,同時也是我自己積累的過程,當然了,我今天給的是一個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

 

ios仿收貨地址管理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.