如果这是一个明显的问题,我很抱歉,但我是原生 iOS 开发的新手,我一直在寻找答案几个小时没有任何成功。
我正在开发一个需要连接到蓝牙 MIDI 键盘的应用程序。我在 Apple 的网站上找到了以下文档,其中描述了如何从应用程序管理蓝牙设备 https://developer.apple.com/library/content/qa/qa1831/_index.html
我能够使用以下代码显示对话框并连接到键盘。问题是,没有办法关闭对话框。对于我在代码中看到的内容,添加了“完成”按钮,但在运行应用程序时它不显示。
- (void)doneActionid)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)configureCentralid)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
actionselector(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 本身作为导航栏的一些控件,具体取决于当前状态,不确定它是否覆盖了此类按钮
Best Answer-推荐答案 strong>
这对我有用(适用于 iPhone 版本):
- (void)doneActionid)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}
- (IBAction)configureCentralid)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)configureLocalPeripheralUIButton *)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/
|