进入页面列表页面的时候可能 会有二级列表,数据默认是二级列表的第一个栏目下的数据,所以,默认情况下第一个 应该是选中的状态
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];
}