iOS-HQSliderView點擊不同Button切換tableViewCell

來源:互聯網
上載者:User

效果:
 代碼如下 複製代碼
1.自訂的點擊Button切換不同TableViewCell,效果如圖所示

HQSliderView.gif
使用教程:
 代碼如下 複製代碼
2.1 匯入HQSliderView

拷貝HQSliderView到項目中.png
 代碼如下 複製代碼
2.2 viewDidLoad方法裡面
- (void)viewDidLoad {    [super viewDidLoad];    self.view.backgroundColor = [UIColor whiteColor];    [self setupTopSliderView];    [self setupTableView];}
 代碼如下 複製代碼
2.3 建立上部SliderView
#pragma mark - 建立上部SliderView- (void)setupTopSliderView{    HQSliderView *sliderView = [[HQSliderView alloc] initWithFrame:CGRectMake(0, NAV_HEIGHT, SCREEN_WIDTH, SLIDER_HEIGHT)];    sliderView.titleArr = @[@"全部", @"待付款", @"已付款", @"退款"];    sliderView.delegate = self;    [self.view addSubview:sliderView];}
 代碼如下 複製代碼
2.4 建立TableView
#pragma mark - 建立TableView- (void)setupTableView{    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NAV_HEIGHT + SLIDER_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - NAV_HEIGHT)];    tableView.dataSource = self;    [self.view addSubview:tableView];    self.tableView = tableView;}
 代碼如下 複製代碼
2.5 實現TableView的資料來源方法
#pragma mark - UITableViewDataSource- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    if (self.menuTag == 0) {        return 3;    } else if (self.menuTag == 1) {        return 6;    } else if (self.menuTag == 2) {        return 9;    } else {        return 12;    }}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    HQTableViewCell *cell = [HQTableViewCell tableViewCellWithTableView:tableView];    if (self.menuTag == 0) {        cell.textLabel.text = [NSString stringWithFormat:@"全部 --- 第%ld行", indexPath.row];    } else if (self.menuTag == 1) {        cell.textLabel.text = [NSString stringWithFormat:@"待付款 --- 第%ld行", indexPath.row];    } else if (self.menuTag == 2) {        cell.textLabel.text = [NSString stringWithFormat:@"已付款 --- 第%ld行", indexPath.row];    } else {        cell.textLabel.text = [NSString stringWithFormat:@"退款 --- 第%ld行", indexPath.row];    }    return cell;}
 代碼如下 複製代碼
2.6 實現HQSliderView的代理方法
#pragma mark - HQSliderViewDelegate- (void)sliderView:(HQSliderView *)sliderView didClickMenuButton:(UIButton *)button{    self.menuTag = button.tag;    [self.tableView reloadData];}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.