iOS 模拟器与 iPad 2、UIBarButtonItem 不一致

发布于 2024-11-27 19:03:38 字数 1176 浏览 4 评论 0原文

昨天发生了一些有趣的事情,我不知道其他人是否也发生过。我基本上根据在 tabbarcontroller 中选择的选项卡将 UIBarButtonItem 添加到工具栏。例如,在选项卡 2 中,我像这样添加它:

NSMutableArray *barItems = [[self.MainToolbar items] mutableCopy];
            if (_sortButton == nil) {
                _sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStyleBordered target:self action:@selector(sortButtonPressed:)];
            }
            [barItems insertObject:_sortButton atIndex:0];
            [self.MainToolbar setItems:barItems];
            [barItems release];

同样,当我删除按钮时,我这样做:

if (_sortButton != nil) {
            self.SortButton = nil;
            NSMutableArray *barItems = [[self.MainToolbar items] mutableCopy];
            [barItems removeObjectAtIndex:0];
            [self.MainToolbar setItems:barItems];
            [barItems release];
        }

所以在模拟器上,它工作正常。我可以在选项卡之间切换,在应用程序中导航,而且我还没有看到该按钮出现问题。我还用仪器测试了此功能,没有发现任何明显的问题。然后当我把它放在实际的 iPad 2 上时,当我第一次单击该选项卡时,它显示得很好,然后我单击了另一个选项卡,然后单击回到选项卡 2,按钮将移至向右一点(它一开始就位于工具栏的左侧)。然后你点击离开,再回来,它再次向右移动。还不知道为什么会发生这种情况,但我也不确定为什么它只发生在设备上,而不是在模拟器中发生这样的事情。我绝对知道应该始终在实际硬件上进行测试,但只是想知道这是否是其他人已知的问题。谢谢!

So something interesting happened yesterday that I don't know if it's ever happened to someone else. I basically add a UIBarButtonItem to the tool bar based on which tab is selected in the tabbarcontroller. For example, in tab 2, I add it like this:

NSMutableArray *barItems = [[self.MainToolbar items] mutableCopy];
            if (_sortButton == nil) {
                _sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStyleBordered target:self action:@selector(sortButtonPressed:)];
            }
            [barItems insertObject:_sortButton atIndex:0];
            [self.MainToolbar setItems:barItems];
            [barItems release];

Similarly, when I remove the button, I do this:

if (_sortButton != nil) {
            self.SortButton = nil;
            NSMutableArray *barItems = [[self.MainToolbar items] mutableCopy];
            [barItems removeObjectAtIndex:0];
            [self.MainToolbar setItems:barItems];
            [barItems release];
        }

So on the simulator, it works fine. I can switch between tabs, navigate through the app, and I have not seen problems with the button. I have also tested this functionality with instruments and did not see any obvious problems. Then when I put it on the actual iPad 2, when I would click on the tab the first time, it showed up fine, then I clicked on a different tab, then clicked back to the tab 2, and the button would move to the right a little bit (it's positioned all the way on the left of the tool bar at the start). Then you click away, and come back, and again, it moves more to the right. Not sure why it's happening yet, but I was also unsure why it only happened on the device, and not in the simulator for something like this. I definitely know that things should always be tested on the actual hardware, but just wondering if this is a known problem to others. Thanks!

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

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

发布评论

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

评论(1

不再让梦枯萎 2024-12-04 19:03:38

我有一个类似的问题。

就我而言,出于某种原因,.png 文件已从项目和项目的工作目录中删除。
因此,它不再包含在复制捆绑资源中。

但奇怪的是,它显然仍在模拟器上。就我而言,它甚至仍在调试设备上。但是,当构建一个用于临时分发的 Boulder 时,它不存在。因此,完整的按钮(导航栏中的栏按钮项)没有出现。用户无法调用与其关联的操作。

首先,我从模拟器中删除了该应用程序。我都尝试了,从模拟器的 gui 和文件系统 /Users//Library/Application Support/iPhone Simulator/5.0/Applications/(app id)/... 中删除它。在这两种情况下,在模拟器上运行应用程序都会重新安装未使用的 .png 文件以及故意从我的 xcode 项目中删除的许多其他文件。

然而,最终的解决方案是在 xcode 项目中再次包含 png 文件并将其分配给所有相关目标。就我而言,无论如何我都要更改图形,因此我包含了新文件而不是旧文件。但我确信这个细节并不重要。

简短版本:
1. 如果您的 png 文件仍然是项目的一部分,请将其删除。也从项目文件夹中删除ist,只是为了保存。
2. 将 png 文件重新包含到项目中。
3. 创建您的版本并在空设备上尝试。

I had a simiilar issue.

In my case the .png file was erased from the project and from the project's working directory - for some reason.
Consequentally it was not included in the Copy Bundle Resources anymore.

Strange, though, apparently it was still on the simulator. In my case it was even still on the debug device. But when building a boulde for ad-hoc distribution it was not in. As a result the full button (bar button item in the navigation bar) did not appear. Users were unable to invoce the action associated with it.

First I erased the app from the simulator. I tried both, erasing it from the simulator's gui and from the file system /Users//Library/Application Support/iPhone Simulator/5.0/Applications/(app id)/... . In both cases running the app on the simulatore re-installed the unused .png file and a number of other files that were intentionally deleted from my xcode project.

However, the final solution was to include the png file again in the xcode project and assign it to all relevant targets. In my case I was about to change the graphic anyway so I included the new file instead of the old one. But I am sure that this detail does not matter much.

Short version:
1. If your png file is still part of the project, then delete it. Delete ist from the project folder too, just to be save.
2. Re-include the png file to the project.
3. Create your build and try it on an empty device.

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