iphone - 无法在 actionSheet-delegate 方法中设置 tabBarItem-title

标签 iphone ios uikit

我正在使用 UIActionSheet 的方法 showFromTabBar: 来显示操作表。在委托(delegate)方法 actionSheet:clickedButtonAtIndex: 中,我尝试通过调用 self.tabBarItem.title=@"New Title"< 来更改当前 UITabBarItem 的标题,其中 self 是当前 TabBarController 的 ViewController。当我这样做时,TabBarItem 的标题变成空字符串(“”)。当我在操作表的委托(delegate)方法中发布 NSNotification 并尝试以相同的方式更改通知处理程序方法中的标题时,应用程序崩溃(控制台上没有任何输出)。但是当我调用 [self.tabBarItem PerformSelectorOnMainThread:@selector(setTitle:) withObject:@"New Title"waitUntilDone:NO] 时,它适用于这两种变体。这是 SDK 中的一个错误,不是吗?

最佳答案

基本上,UIActionSheet 在调用 actionSheet:clickedButtonAtIndex: 期间阻塞了主线程(或者至少与其交互),可能是由于呈现的结果通过/来自 UITabBar

您实际上是在安排 setTitle: 任务稍后通过 performSelectorOnMainThread:withObject:waitUntilDone:NO 调用完成。这会工作得很好。它与使用这样的 block 非常相似(即使不完全相同):

dispatch_async(dispatch_get_main_queue(), ^{
    self.tabBarItem.title = @"New Title";
});

如果该语法更适合您,那就太好了。

但是还有一个更简单的方法。 只需使用委托(delegate)方法 actionSheet:didDismissWithButtonIndex: 顾名思义,当 UIActionSheet 已经解除,因此它不会再阻止您的其他调用。

关于iphone - 无法在 actionSheet-delegate 方法中设置 tabBarItem-title,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8624065/

相关文章:

ios - 使用mac中的用户名进行身份验证

ios - iOS 上的文本模糊/锯齿状

ios - 以编程方式更改导航栏标题 : Add a symbol and change its color

ios - 使默认 session 无效 - NSURLSession

ios - swift 正则表达式 : Replace Lowercase Followed by Uppercase

ios - 优化向 UIStackView 添加 View

iphone - 我们可以使用应用程序更改设备时间吗?

ios - 红色 cocoa pod 文件

iphone - 了解iPhone上的内存消耗

ios - 表和数组