UISegmentedControl 不起作用
您好,我尝试使用分段控件在三个地图视图之间交换,但它不起作用。
我的IBAction方法如下。
- (IBAction)segmentSwitch:(id)sender {
NSLog(@"inside segmented switch");
NSLog(@"selected segment %@",selectedSegment);
if (selectedSegment == 0) {
mapView.mapType = MKMapTypeStandard;
}
else{
mapView.mapType = MKMapTypeHybrid;
}
}
我已将 UISegementedControl 声明为插座并将其连接到 xib 视图。我还将这种方法与内部/外部的触地/触地联系起来。它仍然不打印上面给出的 NSLog 命令。这意味着这个方法根本没有被访问?
Hi im trying to use segmented control to swap between three map views however its not working.
My IBAction method is as follows.
- (IBAction)segmentSwitch:(id)sender {
NSLog(@"inside segmented switch");
NSLog(@"selected segment %@",selectedSegment);
if (selectedSegment == 0) {
mapView.mapType = MKMapTypeStandard;
}
else{
mapView.mapType = MKMapTypeHybrid;
}
}
I have declared UISegementedControl as an outlet and connected it to the xib view. I have also connected this method with touch down/touch up inside/outside. It still doesn't print the NSLog commands given above. Which means this method is not accessed at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
快速总结如何在 IB 中为处理两个以上段的用户设置 UISegmentedControl:
IBOutlet UISegmentedControl *segmentControl;
(或将其设置为 @property)- (IBAction) SegmentedControlIndexChanged:(id)sender;
在 .h 中 @end 之前在最近的 iOS 版本中,每种情况都需要大括号:否则会出现错误。这还显示了一些布尔标记来跟踪哪个段是活动的,也许是为了你的 willDisplayCell 方法。
Quick summary of how to set up a UISegmentedControl in IB for those dealing with more than two segments:
IBOutlet UISegmentedControl *segmentControl;
in @interface (or set it as @property)- (IBAction)segmentedControlIndexChanged:(id)sender;
in .h before @endIn recent iOS versions, you need the braces for each case: or you will get errors. This also shows some bool flagging to keep track of what segment is active, maybe for your willDisplayCell method.
希望您选择了正确的方法
ValueChanged
并且您已正确连接该方法的插座。您现在唯一需要做的就是用您的代码替换您的代码。
尝试用您的代码替换此代码。
希望这对您有帮助。
Hope you have selected the right method
ValueChanged
and also you have connected the outlet of your method properly.The only thing you need to do now is to replace your code with your code.
Try replacing this code with your code.
Hope this helps you.
您应该使用 ValueChanged 操作来检测段的切换。
selectedSegment
是您的UISegmentedControl
吗?那么你的代码应该是这样的:
You should use the ValueChanged action for detecting the the switch of segments.
Is
selectedSegment
yourUISegmentedControl
?Then you code should be like: