2

我有一个导航栏,右侧有三个按钮(导航箭头+一个共享按钮)。在 Iphone 模拟器上,我可以很好地看到它们,并且它们运行良好。当我在真正的 Iphone 4 设备上安装应用程序时,按钮根本不显示!!!(我的模拟器是 iPhone 3,如果可以的话)。我的代码是:

UIToolbar *tools = [[UIToolbar alloc]
                    initWithFrame:CGRectMake(0, 0, 70.0f,     44.01f)]; // 44.01 shifts it up 1px for some reason
tools.clearsContextBeforeDrawing = NO;
tools.clipsToBounds = NO;
tools.tintColor = [UIColor colorWithWhite:0.305f alpha:0.0f]; // closest I could get by eye to black, translucent style.
// anyone know how to get it perfect?
tools.barStyle = -1; // clear background


NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];

// Create a standard refresh button.
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(shareClicked)];
//initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
[buttons addObject:bi];
[bi release];

// Create a spacer.
bi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"scroll left.png"] style:UIBarButtonItemStylePlain target:self action:@selector(upClicked)];
//bi.width = 12.0f;
[buttons addObject:bi];
[bi release];

// Add profile button.
bi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"scroll right.png"] style:UIBarButtonItemStylePlain target:self action:@selector(downClicked)];
//bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];

// Add buttons to toolbar and toolbar to nav bar.
[tools setItems:buttons animated:NO];
[buttons release];
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
self.navigationItem.rightBarButtonItem = twoButtons;
[twoButtons release];
4

3 回答 3

6

我有一个类似的问题。

在我的情况下,.png 文件已从项目和项目的工作目录中删除 - 出于某种原因。因此,它不再包含在 Copy Bundle Resources 中。

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

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

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

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

于 2012-01-21T16:43:32.323 回答
1

还遇到了 XCode Simulator 显示自定义导航右栏按钮但设备没有的问题。错误是自定义按钮的弱属性 IBOutlet。检查您的 IBOutlet @property。在我的情况下,修复只是将 IBOutlet 更改为:@property(nonatomic, retain) IBOutlet UIButton *customBtn;

于 2015-07-29T15:32:52.247 回答
0

就我而言,我以某种方式删除了对我的自定义图像的引用。从图像列表中再次选择名称解决了这个问题。

在此处输入图像描述

于 2016-06-06T10:13:05.170 回答