我正在尝试在 Xcode 5 中以编程方式将连接按钮添加到我的项目中,类似于此链接中示例的概念中显示的按钮:
我正在使用的代码如下所示:
- (void) setupConnectButton
{
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:self.peripheral.isConnected ? NSLocalizedString(@"Disconnect", nil) : NSLocalizedString(@"Connect", nil) style:UIBarButtonItemStyleBordered target:self action:@selector(connectAction:)];
self.navigationItem.leftBarButtonItem = item;
self.navigationItem.leftBarButtonItem.enabled = (self.peripheral != nil);
self.beatsPerMinute.hidden = !self.peripheral.isConnected;
self.legendLabel.hidden = !self.peripheral.isConnected;
}
但是,当我启动应用程序时,按钮没有出现......是否可能是因为我创建的图表以某种方式阻止了视图中的按钮?
编辑:我正在使用与 Apple AcceleratorGraph 项目中相同的代码创建图表:https ://developer.apple.com/library/IOS/samplecode/AccelerometerGraph/Introduction/Intro.html
绘制图形的代码如下所示:
// The graph view itself exists only to draw the background and gridlines. All other content is drawn either into
// the GraphTextView or into a layer managed by a GraphViewSegment.
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
// Fill in the background
CGContextSetFillColorWithColor(context, graphBackgroundColor());
CGContextFillRect(context, self.bounds);
CGFloat width = self.bounds.size.width;
CGContextTranslateCTM(context, 0.0, 56.0);
// Draw the grid lines
DrawGridlines(context, 0.0, width);
}