我一直UIAlertController在以前的应用程序中使用,但这次我遇到了一个奇怪的错误.这是我用来呈现它的代码:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:ALERT_TITLE_STRING message:message preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:OK_STRING style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alertController animated:YES completion:^{
}];
Run Code Online (Sandbox Code Playgroud)
一切都很好,但现在我的应用程序在最后一行崩溃了.这是错误:
此应用程序正在从后台线程修改autolayout引擎,这可能导致引擎损坏和奇怪的崩溃.这将在将来的版本中导致异常.
我没有autolayout在我的应用程序中使用.我不知道为什么我会收到这个错误.
有线索吗?
当用户单击 tableviewcell 中的元素时,我想呈现一个新的 ViewController。然而,用于启动 VC 的标准代码在 tableview 单元格中不起作用,甚至在助手类中不起作用,因为 TVC 和助手类都无法呈现视图控制器。
这是辅助类中的代码。无论是放置在 helperclass 还是 tableview cell 中,它都没有启动 VC 的当前方法。
class launchVC {
func launchVCNamed(identifier: String) {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let secondVC = storyBoard.instantiateViewController(withIdentifier: "contactDetail")
//FOLLOWING LINE HAS ERROR NO SUCH MEMBER (present)
self.present(secondVC, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何修改它来启动 VC?
我有一个视图控制器,我在另一个视图控制器上模态呈现,顶级VC的背景视图具有模糊效果.当我使用以下代码时,顶视图控制器显示在底部视图控制器上,但顶部控制器隐藏在导航栏后面:
MOSettingsViewController *settingsViewController = [[MOSettingsViewController alloc]init];
settingsViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
settingsViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
[self presentViewController:settingsViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
当我删除该行时settingsViewController.modalPresentationStyle...,新的视图控制器出现在导航栏上,但呈现视图控制器变为黑色,并破坏模糊效果.
我如何得到这两个演示文稿的混合,其中呈现视图控制器保持可见并且导航栏位于呈现的视图控制器下?
objective-c modalviewcontroller ios presentviewcontroller uivisualeffectview
谢谢您阅读此篇.我想有一个函数Swift文件,我把我的项目的所有函数放入其中,其他Swift文件可以调用.我试图在函数文件中创建一个警报函数,当我传入一个特定的字符串时,它会显示一个特定的警报.当它在主文件中时它正在工作,但当我将它移动到函数文件时,presentViewController给我一个错误,说"使用未解析的标识符'presentViewController'." 请帮忙!这是我的代码:在函数文件中:
import Foundation
import UIKit
/**********************************************
Variables
***********************************************/
var canTapButton: Bool = false
var tappedAmount = 0
/**********************************************
Functions
***********************************************/
//the alert to ask the user to assess their speed
func showAlert(alert: String) -> Void
{
if(alert == "pleaseAssessAlert")
{
let pleaseAssessAlert = UIAlertController(title: "Welcome!", message: "If this is your firs time, I encourage you to use the Speed Assessment Tool (located in the menu) to figure which of you fingers is fastest!", preferredStyle: .Alert)
//ok button
let okButtonOnAlertAction …Run Code Online (Sandbox Code Playgroud) 你好我有点问题.
我有一个项目的应用程序,但它是一个有点旧的应用程序(IOS 7).
我在互联网上看到如何使用好的旧UIAlertView的INSTEAD更新UIAlertController.
if (error.code) {
cancelBlock = block;
UIAlertController *alert = [UIAlertController alertControllerWithTitle: @"Message"
message: @"Peripheral Disconnected with Error"
preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle: @"OK"
style: UIAlertActionStyleDestructive
handler: ^(UIAlertAction *action) {
NSLog(@"OK");
}];
[alert addAction: alertAction];
[self presentViewController: controller animated: YES completion: nil];
/* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Peripheral Disconnected with Error"
message:error.description
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];*/
Run Code Online (Sandbox Code Playgroud)
我收到一个我不明白的错误:
'RFduino'没有可见的@interface声明选择器'presentViewController:animated:completion'
我目前有一个基本视图控制器说AVC,它呈现另一个视图控制器说BVC在当前上下文中,如下所示:
let bvc: BVC = sb.instantiateViewControllerWithIdentifier("BVC") as! BVC
bvc.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
self.presentViewController(bvc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
然后我在BVC和dismiss中设置一个值,使用相同的值在AVC的viewWillAppear中执行一个函数.但是,我注意到在提示OverCurrentContext时,在关闭时,viewWillAppear不会被调用.
我该如何解决这个问题?我需要一个半透明的呈现视图,因此需要使用OverCurrentContext.
谢谢!
我有一个视图,我想显示一个自定义大小的UIViewController.但我没有成功.这是我的代码.
var vx = KeyboardViewController()
vx.modalPresentationStyle = UIModalPresentationStyle.FormSheet
vx.preferredContentSize = CGSizeMake(self.view.frame.width, 150)
self.presentViewController(vx, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
此UIViewController以全屏大小显示
假设我们有一个自定义控件,在某些状态下应弹出选项列表供用户选择(UIAlertController).通常当我们在视图控制器中时,我们使用presentViewController方法,但在这种情况下,我们无法访问保存此方法的父UIViewController.虽然似乎有一些方法可以从子视图中获取UIViewController,但它被认为是针对MVC设计模式的.那你怎么这样做?我想保持视图控制器尽可能精简,自定义视图(uicontrol)自给自足,所以我不想将此逻辑移动到视图控制器.虽然欢迎并赞赏您的所有建议和建议.
uiviewcontroller ios presentviewcontroller swift uialertcontroller
在我的情节提要中,有导航控制器,viewContrl1和viewContrl2。对于下一次更新,我必须设法将viewContrl2隔离到viewContrl2的另一个实例。
从stackOverflow获得一些帮助后,我通过以下方式进行了管理:
let newView2 : ViewContrl2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("viewContrl2") as! ViewContrl2
...
...
view2.presentViewController(newView2, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
实际上,它确实满足我的需求,但顶部没有NavigationBar。在ViewContrl2类中,有@IBOutlet弱变量导航:UINavigationItem !,我直接从StoryBoard连接。但是,似乎导航在新创建的viewContrl2中不起作用。我需要这样做是因为用户必须能够按“返回”并返回上一个视图。任何人都可以解决这个问题吗?
谢谢
uinavigationcontroller uinavigationitem ios presentviewcontroller swift
嗨,我使用此代码仅使用代码而不使用 segue 移入新的控制器。
UIStoryboard * mainstoryb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * vc = [mainstoryb instantiateViewControllerWithIdentifier:@"online_shop"];
[self presentViewController:vc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
如何在下一个视图中显示导航栏或标题栏?