草庐IT

ios - 无法将 "Done"按钮添加到 CABTMIDICentralViewController

coder 2024-01-18 原文

如果这是一个明显的问题,我很抱歉,但我是原生 iOS 开发的新手,我已经搜索了几个小时的答案但没有成功。

我正在开发一个需要连接到蓝牙 MIDI 键盘的应用程序。我在 Apple 的网站上找到了以下文档,其中描述了如何从应用程序管理蓝牙设备 https://developer.apple.com/library/content/qa/qa1831/_index.html

我能够使用以下代码显示对话框并连接到键盘。问题是,没有办法关闭对话框。对于我在代码中看到的内容,添加了“完成”按钮,但在运行应用程序时它不显示。

- (void)doneAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)configureCentral:(id)sender
{
    CABTMIDICentralViewController *viewController = [CABTMIDICentralViewController new];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];

    // this will present a view controller as a popover in iPad and modal VC on iPhone
    viewController.navigationItem.rightBarButtonItem =
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                      target:self
                                                      action:@selector(doneAction:)];

    navController.modalPresentationStyle = UIModalPresentationPopover;

    UIPopoverPresentationController *popC = navController.popoverPresentationController;
    popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
    popC.sourceRect = [sender frame];

    UIButton *button = (UIButton *)sender;
    popC.sourceView = button.superview;

    [self presentViewController:navController animated:YES completion:nil];
}

CABTMIDICentralViewController 本身作为导航栏的一些控件,具体取决于当前状态,不确定它是否覆盖了此类按钮

最佳答案

这对我有用(对于 iPhone 版本):

- (void)doneAction:(id)sender {
  [self dismissViewControllerAnimated:NO completion:nil];
}

- (IBAction)configureCentral:(id)sender {

  CABTMIDICentralViewController *viewControllerBT = [CABTMIDICentralViewController new];

  UINavigationController *navControllerBT = [[UINavigationController alloc] initWithRootViewController:viewControllerBT];

  UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  btn.frame = CGRectMake(screenSize.width-60, 40, 60, 40);
  btn.titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
  [btn setTitle:@"Done" forState:UIControlStateNormal];
  [btn addTarget:self action: @selector(doneAction:) forControlEvents: UIControlEventTouchDown];
  [navControllerBT.view addSubview:btn];

  [self presentViewController:navControllerBT animated:NO completion:nil];

}

- (IBAction)configureLocalPeripheral:(UIButton *)sender {

  CABTMIDILocalPeripheralViewController *viewControllerBTA = [[CABTMIDILocalPeripheralViewController alloc] init];

  UINavigationController *navControllerBTA = [[UINavigationController alloc] initWithRootViewController:viewControllerBTA];

  UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  btn.frame = CGRectMake(screenSize.width-60, 40, 60, 40);
  btn.titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
  [btn setTitle:@"Done" forState:UIControlStateNormal];
  [btn addTarget:self action: @selector(doneAction:) forControlEvents: UIControlEventTouchDown];
  [navControllerBTA.view addSubview:btn];

  [self presentViewController:navControllerBTA animated:NO completion:nil];

}

关于ios - 无法将 "Done"按钮添加到 CABTMIDICentralViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39547797/

有关ios - 无法将 "Done"按钮添加到 CABTMIDICentralViewController的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  3. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  4. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  5. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  6. ruby - 将 Bootstrap Less 添加到 Sinatra - 2

    我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它

  7. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  8. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  9. ruby - 续集在添加关联时访问many_to_many连接表 - 2

    我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以

  10. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

随机推荐