当 navController 返回时 UIButton 丢失文本标签
我有一个带有“名称”标签的自定义 UIButton。当用户单击此按钮时,它会加载另一个显示名称列表的视图,点击名称会弹出此视图,并使用所选名称更新 UIButton。
那部分有效。如果用户没有从视图中选择名称,而只是点击“返回”,则不起作用。视图被弹出,但现在 UIButton 文本“Name”被删除,按钮文本完全空白。 如何阻止文本标签被擦除?
我没有任何代码可以更新 UIButton 标签除非如果点击一行(didSelectARowAtIndexPath)所以我不明白加载新视图时如何清除标签“Name”。请注意,我有三个具有类似功能的按钮,并且点击时只会删除相应按钮的文本 - 其他两个不受影响。
I have a custom UIButton that has the label "Name". When the user clicks this button, it loads another View that displays a list of names, and tapping a name pops this View off, and updates the UIButton with the selected name.
That part works. What doesn't work is if the user doesn't select a name from the View, but instead just hits Back. The view is popped off, but now the UIButton text "Name" is removed, and the button text is completely blank. How do I stop the text label from being erased?
I don't have any code that updates the UIButton label except if a row is tapped (didSelectARowAtIndexPath) so I don't understand how the label "Name" is being cleared upon loading a new View. Note that I have three of these buttons w/similar functionality, and only the text of the respective button is erased when tapped - the other two aren't impacted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在调用 Button.titleLabel.text = @"Name";或者它的非点属性版本。如果是这样那就是你的问题了。您需要致电
[按钮setTitle:@"名称" forState:UIControlStateNormal];否则当按钮改变状态时标题将会丢失。如果那不是您的问题,请发布一些代码。
Are you calling Button.titleLabel.text = @"Name"; or the non dot property version of that. If so that's your problem. You need to call
[Button setTitle:@"Name" forState:UIControlStateNormal]; otherwise the title will be lost when the button changes state. If thats not your issue then please post some code.
在
didSelectARowAtIndexPath
方法中设置断点并查看从何处调用它。您可以阅读 Apple 的调试应用程序 文档以了解有关使用 XCode 调试器的更多信息,或者您也可以Google 搜索“xcode 调试教程”。Set a breakpoint in your
didSelectARowAtIndexPath
method and see where it is being called from. You can read Apple's Debugging Applications document for more on using XCode's debugger, or you can just google for "xcode debugging tutorial".