ios - 无法将 "Done"按钮添加到 CABTMIDICentralViewController
<p><p>如果这是一个明显的问题,我很抱歉,但我是原生 iOS 开发的新手,我一直在寻找答案几个小时没有任何成功。</p>
<p>我正在开发一个需要连接到蓝牙 MIDI 键盘的应用程序。我在 Apple 的网站上找到了以下文档,其中描述了如何从应用程序管理蓝牙设备 <a href="https://developer.apple.com/library/content/qa/qa1831/_index.html" rel="noreferrer noopener nofollow">https://developer.apple.com/library/content/qa/qa1831/_index.html</a> </p>
<p>我能够使用以下代码显示对话框并连接到键盘。问题是,没有办法关闭对话框。对于我在代码中看到的内容,添加了“完成”按钮,但在运行应用程序时它不显示。</p>
<pre><code>- (void)doneAction:(id)sender
{
;
}
- (IBAction)configureCentral:(id)sender
{
CABTMIDICentralViewController *viewController = ;
UINavigationController *navController = [ initWithRootViewController:viewController];
// this will present a view controller as a popover in iPad and modal VC on iPhone
viewController.navigationItem.rightBarButtonItem =
[ initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(doneAction:)];
navController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popC = navController.popoverPresentationController;
popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popC.sourceRect = ;
UIButton *button = (UIButton *)sender;
popC.sourceView = button.superview;
;
}
</code></pre>
<p>CABTMIDICentralViewController 本身作为导航栏的一些控件,具体取决于当前状态,不确定它是否覆盖了此类按钮</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这对我有用(适用于 iPhone 版本):</p>
<pre><code>- (void)doneAction:(id)sender {
;
}
- (IBAction)configureCentral:(id)sender {
CABTMIDICentralViewController *viewControllerBT = ;
UINavigationController *navControllerBT = [ initWithRootViewController:viewControllerBT];
UIButton * btn = ;
btn.frame = CGRectMake(screenSize.width-60, 40, 60, 40);
btn.titleLabel.font = ;
;
;
;
;
}
- (IBAction)configureLocalPeripheral:(UIButton *)sender {
CABTMIDILocalPeripheralViewController *viewControllerBTA = [ init];
UINavigationController *navControllerBTA = [ initWithRootViewController:viewControllerBTA];
UIButton * btn = ;
btn.frame = CGRectMake(screenSize.width-60, 40, 60, 40);
btn.titleLabel.font = ;
;
;
;
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 无法将"Done"按钮添加到 CABTMIDICentralViewController,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39547797/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39547797/
</a>
</p>
页:
[1]