开发者

iOS Simulator inconsistent with iPad 2, UIBarButtonItem

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.开发者_StackOverflow中文版 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜