我正在使用以下代码以编程方式导航到另一个ViewController.它工作正常,但有些隐藏了navigation bar.我该如何解决?(导航栏被embeding创建ViewController的navigation controller,如果该事项).
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
self.presentViewController(nextViewController, animated:true, completion:nil)
Run Code Online (Sandbox Code Playgroud) 我尝试下一个代码片段:
var alert = UIAlertController(title: "Alert", message: "Cannot connect to : \(error!.localizedDescription)", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在我的AppDelegate中,但它在控制台中打印出下一个错误:
Warning: Attempt to present <UIAlertController: 0x7ff6cd827a30> on <Messenger.WelcomeController: 0x7ff6cb51c940> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
我想从一个显示警报消息viewDidLoad()的方法,ViewController.m从替代viewDidAppear()方法.
这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
//A SIMPLE ALERT DIALOG
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Enter User Credentials"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"OK action");
}];
[alert addAction:cancelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
警告:试图提出
<UIAlertController: 0x7fbc58448960>对<ViewController: 0x7fbc585a09d0>他们的看法是不是在窗口层次!
我在iOS 7中测试新的条形码扫描api时出了问题.这个例子(单视图应用程序)工作正常,但我想停止AVCaptureSession并在摄像机识别出EAN代码后显示第一个视图.
[self.captureSession startRunning]; 不起作用.
我如何正确停止AVCaptureSession?
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController () <AVCaptureMetadataOutputObjectsDelegate>
@property (strong) AVCaptureSession *captureSession;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
if(videoInput)
[self.captureSession addInput:videoInput];
else
NSLog(@"Error: %@", error);
AVCaptureMetadataOutput *metadataOutput = [[AVCaptureMetadataOutput alloc] init];
[self.captureSession addOutput:metadataOutput];
[metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[metadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code]];
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
previewLayer.frame = self.view.layer.bounds;
[self.view.layer addSublayer:previewLayer];
[self.captureSession startRunning]; …Run Code Online (Sandbox Code Playgroud) 在我的应用程序上,我有一个cameraOverlayView打开相机,带有自定义控件,用于相机按钮.该应用程序允许用户在关闭相机之前拍摄多张照片,因此快门按钮不会调用dismissViewControllerAnimated,而是在您完成拍照时有一个关闭按钮.
现在,相机覆盖图上的一个按钮是一个图库按钮,允许用户选择保存的图像而不是拍摄新的图像.我尝试了两种不同的方法来完成这项工作,但都失败了.
第一种方法
使用UIImagePickerController当前显示叠加层的相同实例并切换sourceType到库.它确实呈现了画廊,但是当拍摄照片时,我不能在不解雇整个叠加层的情况下解雇厨房.
第二种方法
创建一个单独的实例UIImagePickerController,设置sourceType为库并尝试调用presentViewController,然后失败并显示警告:
"警告:尝试在窗口层次结构中显示其视图!"
有没有人有这个问题的解决方案?这甚至可能吗?
好吧,所以我对Swift很新,我对我要做的事情有点困惑,或者我是否朝着错误的方向前进.(https://github.com/ashleymills/Reachability.swift)
这是我的viewDidLoad方法:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
checkConnection()
}
Run Code Online (Sandbox Code Playgroud)
然后,我从Reachability GitHub项目中获得了一个带有代码的函数:
func checkConnection() {
//declare this property where it won't go out of scope relative to your listener
let reachability = Reachability()!
reachability.whenReachable = { reachability in
// this is called on a background thread, but UI updates must
// be on the main thread, like this:
DispatchQueue.main.async {
if reachability.isReachableViaWiFi {
print("Reachable …Run Code Online (Sandbox Code Playgroud) 我将我的Swift应用程序升级到Xcode 7/Swift 2.0,现在我的应用程序突然发现某些segues不再有效.
我有一个segue弹出一个"Check In"模式并且它完美地工作,但是我有另一个segue弹出一个"Check Out"模式,它几乎相同并且它不会启动并且应用程序被冻结.
我从头开始重新创建了segue,确认它与"Check In"相同,但它仍然不起作用.
相反,我也尝试启动空白视图而不是我的Check Out模式,它工作正常.
没有错误,它只是冻结,我确实正确地调用了"prepareForSegue"部分但是我的模态的"viewDidLoad"部分没有被调用.
仅供参考,我已关闭自动布局.
我有一个警报视图,我试图在照片视图上呈现.
照片显示在列表中,可以推送到全屏视图.
照片视图以编程方式显示.我认为这是导致问题的原因,因为警报视图试图在已经呈现的(照片)视图之上呈现另一个视图.
警报视图正在尝试显示,但是收到此错误:
Warning: Attempt to present <UIAlertController: 0x147d2c6b0> on <LiveDeadApp.ListViewController: 0x147d614c0> which is already presenting (null)
Run Code Online (Sandbox Code Playgroud)
可能有问题的一行是这一行:
self.present(textPrompt, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在主照片视图上拍摄屏幕截图时,不会发生警报视图.但是,当设备的方向发生变化时,照片视图会返回列表并显示警报.

iOS 10中的Swift 3
谢谢!
这是列表视图和照片视图的代码:
import UIKit
import Kingfisher
import SKPhotoBrowser
class ListViewCell: UITableViewCell {
@IBOutlet weak var Cellimage: UIImageView!
@IBOutlet weak var cellVenue: UILabel!
@IBOutlet weak var cellLocation: UILabel!
@IBOutlet weak var cellDate: UILabel!
@IBOutlet weak var aiView: UIActivityIndicatorView!
}
class ListViewController: UITableViewController {
var subcategory:Subcategory!
var objects:[[String:String]] = …Run Code Online (Sandbox Code Playgroud) 我正在尝试链接我的问题,UIViewController但我得到了最后的错误.
Attempt to present ViewController whose view is not in the window hierarchy
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Wokay"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Vibes"];
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
}
}
Run Code Online (Sandbox Code Playgroud)
代码错误:
Warning: Attempt to present <ViewController: 0x110634bc0> on <Login: 0x10951e7f0> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud) 这个问题已被多次询问,但即使在尝试了大部分可能的事情后,我仍然无法找到适合我的解决方案.这是错误消息.
警告:尝试在视图不在窗口层次结构中的<0x7f8f29e17590>上显示!
注意:我没有使用任何导航控制器.
我只是模态地呈现一个视图控制器,我有一个按钮,用于linkedIn注册.但每次我点击"确认"按钮时都会出现此错误,但我无法看到新的linkedIn对话框,尽管它在其他类中工作正常.
大多数解决方案建议在viewDidAppear中处理按钮单击已经尝试过,但它不起作用.
我正在使用此代码打开linkedIn注册表单
linkedinHelper.authorizeSuccess({ [unowned self] (lsToken) -> Void in
print("success lsToken: \(lsToken)")
self.requestProfile()
}, error: { [unowned self] (error) -> Void in
print("Encounter error: \(error.localizedDescription)")
}, cancel: { [unowned self] () -> Void in
print("User Cancelled!")
})
Run Code Online (Sandbox Code Playgroud) ios ×10
swift ×6
objective-c ×4
xcode ×3
ios7 ×2
iphone ×2
uialertview ×2
reachability ×1
xcode7 ×1