switch.hidden = YES 不起作用,插座均已正确设置
我遇到了一个完全让我困惑的问题。请看下面的代码,它来自《Beginning iPhone 4 Development》一书的第 4 章。我对此很陌生:)
- (IBAction)toggleControls:(id)sender
{
if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
{
NSLog(@"Show switches");
[self.leftSwitch setHidden:NO];
[self.rightSwitch setHidden:NO];
[self.doSomethingButton setHidden:YES];
}
else
{
NSLog(@"Hide switches");
[self.leftSwitch setHidden:YES];
[self.rightSwitch setHidden:YES];
[self.doSomethingButton setHidden:NO];
}
}
奇怪的是,它正确记录了这一点,但 ui 控件没有隐藏/显示。 我也尝试过这个(书中原创):
- (IBAction)toggleControls:(id)sender
{
if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
{
NSLog(@"Show switches");
leftSwitch.hidden = NO;
rightSwitch.hidden = NO;
doSomethingButton.hidden = YES;
}
else
{
NSLog(@"Hide switches");
leftSwitch.hidden = YES;
rightSwitch.hidden = YES;
doSomethingButton.hidden = NO;
}
}
I am having a problem that is totally confounding me. Please look at the code below, it is from the book "Beginning iPhone 4 Development" chapter 4. I'm new to this :)
- (IBAction)toggleControls:(id)sender
{
if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
{
NSLog(@"Show switches");
[self.leftSwitch setHidden:NO];
[self.rightSwitch setHidden:NO];
[self.doSomethingButton setHidden:YES];
}
else
{
NSLog(@"Hide switches");
[self.leftSwitch setHidden:YES];
[self.rightSwitch setHidden:YES];
[self.doSomethingButton setHidden:NO];
}
}
The strange thing is that it logs this correctly but the ui controls aren't hiding/showing.
I also tried this (original in book):
- (IBAction)toggleControls:(id)sender
{
if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
{
NSLog(@"Show switches");
leftSwitch.hidden = NO;
rightSwitch.hidden = NO;
doSomethingButton.hidden = YES;
}
else
{
NSLog(@"Hide switches");
leftSwitch.hidden = YES;
rightSwitch.hidden = YES;
doSomethingButton.hidden = NO;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您可能忘记在 Interface Builder 中连接插座。使用断点或NSLog检查调用该方法时leftSwitch和rightSwitch的值。
It sounds like you may have forgotten to wire up your outlets in Interface Builder. Check the values of leftSwitch and rightSwitch when this method is called by using a break point or an NSLog.