Home >Web Front-end >HTML Tutorial >Customized tabBar will light up at the same time when clicking on different pages_html/css_WEB-ITnose
Let me explain this bug first:
When I customized the tabBar, I used 4 buttons instead. The buttons set the clicked and unclicked pictures, and then when switching to different pages, it should be Only one of them clicked, but mine would have multiple or even all of them clicked. It took me a long time to figure out where the problem was.
for (int i=0; i<4; i ) {
//Write the button’s direct parent control bottomBg here and then look for the tag, otherwise it will appear Problem
UIButton * button = (UIButton *)[bottomBg viewWithTag:100 i];
//UIButton * button = (UIButton *)[self.view viewWithTag :100 i];
button.selected = NO;
}
btn.selected = YES;
self.selectedIndex = btn .tag-100;
As shown in the code above, the problem lies in finding the button based on the tag value. It turns out that I was looking for it from self.view, and the button is on bottomBg, and bottomBg is on On self.view, I thought there was no problem if I looked for it directly, but it really didn't work.
So in the future, if you find the control through the tag value, it is best to find it directly from the parent control, and there will be no problem. I don’t know the specific reason why. I don’t know the very specific reason. Anyone who knows can give some guidance~