我試圖在Xcode 5編程方式添加一個連接按鈕,我的項目中創建連接按鈕,類似的概念顯示出在這個環節上所示的例子之一:編程在Xcode5
的我使用的代碼如下所示:
- (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;
}
但是,按鈕沒有出現,當我啓動應用程序...它可能是因爲我在創建視圖以某種方式阻止該按鈕的圖形?
編輯:我使用相同的代碼,如蘋果公司的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);
}
你使用的是導航控制器嗎?你能告訴你如何創建你的「圖表」嗎? – sergio
嗨@sergio,我編輯了這個問題,以顯示如何繪製圖表。 謝謝, 尼克 – narner