iOS 设置Button的 初始选中状态
2015-11-16 15:22
477 查看
进入页面列表页面的时候可能 会有二级列表,数据默认是二级列表的第一个栏目下的数据,所以,默认情况下第一个 应该是选中的状态
比如活动秀 就是 这个二级列表的第一个,下面数据就是它的数据,所以他显示的是选中状态 红色的。
btnMutableArray = [[NSMutableArray alloc]init]; //将button放到数组里面
NSMutableDictionary *titleDic = [[NSMutableDictionary alloc]init];
//这个是二级标题的所有信息的字典 首页返回的
for (int i = 0; i < titleMutableArray.count;
i++) {
titleDic = [titleMutableArray objectAtIndex:i];
allButton = [[UIButton alloc]initWithFrame:CGRectMake(viewWidth/4*i,
0, viewWidth/4, 35)];
[allButton setTitle:titleDic[@"name"] forState:UIControlStateNormal];
classid = [titleDic[@"id"]intValue];
allButton.tag = classid;
allButton.titleLabel.font =
[UIFont systemFontOfSize:14];
[allButton setTitleColor:RGBCOLOR(231,
96, 73) forState:UIControlStateSelected];
[allButton setTitleColor:RGBCOLOR(51,
51, 51) forState:UIControlStateNormal];
allButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[allButton addTarget:self action:@selector(fashionButtonPressed:)forControlEvents:UIControlEventTouchUpInside];
[headerScrollerView addSubview:allButton];
[btnMutableArray addObject:allButton];
}
((UIButton *)[btnMutableArray objectAtIndex:0]).selected=YES; //
关键是这里,设置 数组的第一个button为选中状态
//点击事件
-(void)fashionButtonPressed:(UIButton *)sender{
[myFashionMutableArray removeAllObjects];
[_myfashionTableView reloadData];
((UIButton *)[btnMutableArray objectAtIndex:0]).selected=NO;
//点击其他button之后这里设置为非选中状态,否则会出现2个红色的选中状态
if (sender != allButton) {
allButton.selected = NO;
allButton = sender;
} //这个if是网上抄的,有点神奇
allButton.selected = YES;
_fashionpid = sender.tag;
pageSize = 0;
[self loaddataMethodsWithpid:_fashionpid
page:pageSize number:Baby_NumofList andSord:0];
}
比如活动秀 就是 这个二级列表的第一个,下面数据就是它的数据,所以他显示的是选中状态 红色的。
btnMutableArray = [[NSMutableArray alloc]init]; //将button放到数组里面
NSMutableDictionary *titleDic = [[NSMutableDictionary alloc]init];
//这个是二级标题的所有信息的字典 首页返回的
for (int i = 0; i < titleMutableArray.count;
i++) {
titleDic = [titleMutableArray objectAtIndex:i];
allButton = [[UIButton alloc]initWithFrame:CGRectMake(viewWidth/4*i,
0, viewWidth/4, 35)];
[allButton setTitle:titleDic[@"name"] forState:UIControlStateNormal];
classid = [titleDic[@"id"]intValue];
allButton.tag = classid;
allButton.titleLabel.font =
[UIFont systemFontOfSize:14];
[allButton setTitleColor:RGBCOLOR(231,
96, 73) forState:UIControlStateSelected];
[allButton setTitleColor:RGBCOLOR(51,
51, 51) forState:UIControlStateNormal];
allButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[allButton addTarget:self action:@selector(fashionButtonPressed:)forControlEvents:UIControlEventTouchUpInside];
[headerScrollerView addSubview:allButton];
[btnMutableArray addObject:allButton];
}
((UIButton *)[btnMutableArray objectAtIndex:0]).selected=YES; //
关键是这里,设置 数组的第一个button为选中状态
//点击事件
-(void)fashionButtonPressed:(UIButton *)sender{
[myFashionMutableArray removeAllObjects];
[_myfashionTableView reloadData];
((UIButton *)[btnMutableArray objectAtIndex:0]).selected=NO;
//点击其他button之后这里设置为非选中状态,否则会出现2个红色的选中状态
if (sender != allButton) {
allButton.selected = NO;
allButton = sender;
} //这个if是网上抄的,有点神奇
allButton.selected = YES;
_fashionpid = sender.tag;
pageSize = 0;
[self loaddataMethodsWithpid:_fashionpid
page:pageSize number:Baby_NumofList andSord:0];
}
相关文章推荐
- 仿ios日期选择控件
- iOS LBS相关: 定位和中国特色的位置偏移纠正
- iOS9 获取通讯录信息
- (iOS)控制器的生命周期
- iOS学习之屏蔽SSL认证
- iOS中GIF的制作的简单版本记录 详解
- iOS容易造成循环引用的三种场景,就在你我身边!
- IOS修改webView背景透明以及IOS调用前台js的方法
- iOS开发 - TargetAction
- iOS 中正则表达式的运用
- iOS开发—音乐的播放
- iOS判断机型
- 芒果iOS开发之内存管理二
- iOS学习笔记40-GCD定时器的实现
- 转 WWDC 2013 Session笔记 - iOS7中的ViewController切换
- iOS 设计模式——单例模式
- iOS相机与相册的调用常用代码
- iOS开源项目和库
- ios打开通讯录及点击通讯录时提取相关信息
- iOS-----使用AddressBook管理联系人