单选button

// button 点击方法

- (void)toggle:(UIButton *)button {

if (_dataArr == nil) {

button.userInteractionEnabled = NO;

} else {

//设置按钮不能重复点击

if (button == _tempButton) {

button.selected = !button.selected;

if(button.selected == YES) {

[_listTableView removeFromSuperview];

[self createListView];

_listArr = _dataArr[button.tag - 1800];

[_listTableView reloadData];

_btnTag = button.tag;

} else {

[_listTableView removeFromSuperview];

}

return;

}

//保证同时只有一个按钮被选中

[self selectButton:button];

}

}

// 单选

- (void)selectButton:(UIButton *)button {

//保证同时只有一个按钮被选中

if (_tempButton == nil){

button.selected = YES;

_tempButton = button;

} else if (_tempButton !=nil && _tempButton == button){

button.selected = YES;

} else if (_tempButton!= button && _tempButton!=nil){

_tempButton.selected = NO;

button.selected = YES;

_tempButton = button;

}

if(button.selected == YES) {

[_listTableView removeFromSuperview];

[self createListView];

_listArr = _dataArr[button.tag - 1800];

[_listTableView reloadData];

_btnTag = button.tag;

}

}

你可能感兴趣的:(单选button)