如何将插座附加到 UIToolbar 中的 UISegmentedControl

发布于 2024-08-17 17:55:25 字数 259 浏览 6 评论 0原文

我在应用程序中有一个视图。该视图包含一个 UITableView 和一个 UIToolbar,并且在 UIToolbar 中我有 UISegmentedControl,它包含在 UIBarButtonItem 对象中。

我可以让分段控件链接到 IBAction 事件,然后它根据值更改进行操作,但我看不到如何向此项添加 IBOutlet。

当我尝试添加此链接时,似乎想要接受出口链接的唯一对象是表格视图。我希望这会进入文件所有者的出口。

我在这里缺少什么?

I have a view in an application. The view contains a UITableView and a UIToolbar, and within the UIToolbar I have UISegmentedControl that is contained within a UIBarButtonItem object.

I can get the segmented control to link to an IBAction event, and it then acts upon a value change, but I cannot see how to add an IBOutlet to this item.

When I try to add this link, the only object that appears to want to accept the outlet link is the tableview. I would expect this to be wanting to go into an outlet on the File's Owner.

What am I missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

农村范ル 2024-08-24 17:55:25

实际上,问题是视图未正确分配,并且使用了无效的子类。这阻止了文件所有者允许我查看 IBOutlet - 它已在 .h 文件中正确指定。

一旦我纠正了类层次结构,问题就消失了。

谢谢大家的帮助。

Actually, the problem turned out to be that the view was not correctly assigned, and was using an invalid subclass. That was preventing File's Owner from permitting me to see the IBOutlets - which had already been correctly specified in the .h file.

As soon as I corrected the class hierarchy, the problem went away.

Thanks, all y'all, for your assistance.

暗恋未遂 2024-08-24 17:55:25

你的问题不清楚。

如果您尝试向分段控件添加出口,即从分段控件运行到另一个对象的出口,则必须使用添加的出口属性对分段控件进行子类化。出口是指向外部对象的指针,因此类必须为指针分配内存并为其创建符号。

如果您尝试将文件所有者的出口链接到分段控件,但没有看到文件所有者的出口属性作为选项,那么您要么 (1) 在文件所有者类中错误地定义了出口,要么 (2) 没有将文件所有者设置为正确的类。

对于 (1),在您的文件所有者类中,您应该具有如下所示的内容:

@property (nonatomic, retain) IBOutlet UISegmentedControl *mySegmentedControl; //best

@property id mySegmentedControl; //works but is sloppy unless the flexibility is required

对于 (2) 在界面构建器中,查看身份面板中的检查器,并检查是否将正确的类分配给文件所有者。

Your question is unclear.

If your trying to add an outlet to the segmented control i.e. an outlet that runs from the segmented control to another object, then you have to subclass the segmented control with an added outlet property. An outlet is a pointer to an external object so the class has to allocate memory for the pointer and create a symbol for it.

If your trying to link an outlet from the File Owner to the segmented control but are seeing not seeing the File Owner's outlet property as a choice, then you either (1) have defined the outlet incorrectly in the File Owners class or (2) not set the File Owner to the proper class.

For (1), in your File Owner class you should have something that looks like this:

@property (nonatomic, retain) IBOutlet UISegmentedControl *mySegmentedControl; //best

or

@property id mySegmentedControl; //works but is sloppy unless the flexibility is required

For (2) In interface builder, look in the inspector in the identity panel and check that the proper class is assigned to File Owner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文