我正在使用XCode 8并使用iOS 10.2 Beta进行测试.
我已将Photos,PhotosUI和MobileCoreServices框架添加到项目中.
非常简单的代码:
#import <Photos/Photos.h>
#import <PhotosUI/PhotosUI.h>
#import <MobileCoreServices/MobileCoreServices.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, PHLivePhotoViewDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *imageview;
@end
和实施:
- (IBAction)grab:(UIButton *)sender{
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.allowsEditing = NO;
    picker.delegate = self;
    // make sure we include Live Photos (otherwise we'll only get UIImages)
    NSArray *mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeLivePhoto];
    picker.mediaTypes = mediaTypes;
    // bring up the picker
    [self presentViewController:picker animated:YES completion:nil];
}
一旦我点击按钮,应用程序崩溃时出现非常无用的错误:
[access] <private>
而已.没有其他的. …
objective-c uiimagepickercontroller ios presentviewcontroller ios10
关于如何通过显示和解除多个视图控制器解决问题,我在最后一周打破了我的头脑.我创建了一个示例项目并直接从项目中粘贴代码.我有3个视图控制器及其相应的.xib文件.MainViewController,VC1和VC2.我在主视图控制器上有两个按钮.
- (IBAction)VC1Pressed:(UIButton *)sender
{
    VC1 *vc1 = [[VC1 alloc] initWithNibName:@"VC1" bundle:nil];
    [vc1 setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentViewController:vc1 animated:YES completion:nil];
}
这打开VC1没有问题.在VC1中,我有另一个按钮,它应该打开VC2,同时解除VC1.
- (IBAction)buttonPressedFromVC1:(UIButton *)sender
{
    VC2 *vc2 = [[VC2 alloc] initWithNibName:@"VC2" bundle:nil];
    [vc2 setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentViewController:vc2 animated:YES completion:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
} // This shows a warning: Attempt to dismiss from view controller <VC1: 0x715e460> while a presentation or dismiss is in progress!
- (IBAction)buttonPressedFromVC2:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
} // This is going back to VC1. 
我希望它回到主视图控制器,同时VC1应该已经从内存中删除了.只有当我点击主控制器上的VC1按钮时才会显示VC1.
主视图控制器上的另一个按钮也应该能够直接绕过VC1显示VC2,并且当在VC2上单击按钮时应该返回到主控制器.没有长时间运行的代码,循环或任何计时器.只是裸骨调用来查看控制器.
objective-c uiviewcontroller ios presentviewcontroller dismissviewcontroller
我试图提出一个数据模型中ViewController 是否有任何已保存的数据.但是我收到以下错误:
警告:尝试显示其视图不在窗口层次结构中的*on*
相关代码:
override func viewDidLoad() {
    super.viewDidLoad()
    loginButton.backgroundColor = UIColor.orangeColor()
    var request = NSFetchRequest(entityName: "UserData")
    request.returnsObjectsAsFaults = false
    var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
    var context:NSManagedObjectContext = appDel.managedObjectContext!
    var results:NSArray = context.executeFetchRequest(request, error: nil)!
    if(results.count <= 0){
        print("Inga resultat")
    } else {
        print("SWITCH VIEW PLOX")
        let internVC = self.storyboard?.instantiateViewControllerWithIdentifier("internVC") as internViewController
        self.presentViewController(internVC, animated: true, completion: nil)
    }
}
我尝试过使用谷歌找到的不同解决方案但没有成功.
我以编程方式在iOS Swift项目中拥有多个View Controller.我没有故事板,如果可能的话,我想避免使用它们.有没有办法切换到另一个viewcontroller.swift文件(我们将调用它view2.swift)并让它成为按钮调用的函数的一部分?
我尝试过以下方法:
let storyboard: UIStoryboard = UIStoryboard(name: "myTabBarName", bundle: nil)
let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("myVCID") as UIViewController
self.presentViewController(vc, animated: true, completion: nil)
上面的工作与故事板,但我希望另一个view2.swift被称为.可以这样做吗?
我已经查看了我可以在这个教程中找到的所有教程,但我仍然没有答案.我需要从代码中调用另一个视图.我在用UIStoryboards.我已经通过控制拖动多次更改了视图UIButtons,但现在它必须来自代码.如果是用户第一次打开应用程序,我试图从主菜单调用信息页面.但是,我似乎找不到从代码中更改视图的方法.我的所有视图都由相同的文件控制(ViewController2).在identifier我的主菜单是ViewControllerMain,而identifier该信息页面的是ViewControllerInfo.首先我尝试了这个:
[ViewControllerMain presentViewController: ViewControllerInfo 
                                 animated:YES 
                               completion: NULL];
然后我尝试UIViewControllers为每个人做出不同的说法:
[ViewController2 presentViewController: ViewController 
                              animated:YES 
                            completion: NULL];
都没有奏效.对于第一个,它说:
使用未声明的标识符ViewControllerMain.
在第二个中,它说:
意外的接口名称'ViewController':预期的标识符.
我能做什么?
objective-c uiviewcontroller ios uistoryboard presentviewcontroller
当我尝试在导航控制器上呈现ActivityController时,我收到以下警告,
Attempt to present <UIActivityViewController: 0x15be1d60> on <UINavigationController: 0x14608e80> whose view is not in the window hierarchy!
我试图通过以下代码呈现视图控制器,
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
    activityController.excludedActivityTypes = excludeActivities;
    UIViewController *vc = self.view.window.rootViewController;
    [vc presentViewController: activityController animated: YES completion:nil];
    [activityController setCompletionHandler:^(NSString *activityType, BOOL completed) {
        NSLog(@"completed");
    }];
这里出了什么问题?
objective-c ios uiview-hierarchy uiactivityviewcontroller presentviewcontroller
我正在使用该presentViewController:animated:completion:方法转到另一个视图控制器.
这是我的代码:
AddTaskViewController *add = [[AddTaskViewController alloc] init];
[self presentViewController:add animated:YES completion:nil];
此代码转到另一个,UIViewController但另一个控制器为空.我一直在使用故事板,但现在我需要在代码中完成.
objective-c uiviewcontroller ios uistoryboard presentviewcontroller
简而言之: 我如何从呈现的ViewController中推送PushController?
简单来说 :
我有MainViewController,我点击按钮时有一个按钮,我正在展示一个叫做的视图LoginViewController.
在这个页面上(LoginViewController),我再次button点击它,我尝试推动我的视图控制器(称为HomeViewController)它不会推动.
这是我的代码片段,
MainViewController.m
- (IBAction)LoginClicked:(id)sender {
    LoginViewController *vc = [[LoginViewController alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}
LoginViewController.m
- (IBAction)buttonActionMethodOnLoginView:(id)sender{
     NSLog(@"viewControllers %@",APPDELEGATE.nav.viewControllers);
     //LoginViewController is not in this array
     HomeViewController *obj = [[HomeViewController alloc] init];
     [self.navigationController pushViewController:obj animated:YES];
}
但它对我不起作用.另外,我a stack of view controllers之前打印过pushed,但它没有LoginViewController.因此,无需添加LoginViewController到a stack of view controllers,我怎样才能pushed到HomeViewController从LoginViewController?
当我从中获取时HomeViewController …
objective-c uinavigationcontroller pushviewcontroller ios presentviewcontroller
所以我在iOS7中有一个完整的工作解决方案,通过appDelegate的didFinishLaunching中的presentViewController显示一个LoginViewController.
基本上我做的是这样的:
UIViewController *backgroundViewController = ...
self.window.rootViewController = backgroundViewController;
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:loginViewController
                                             animated:NO ...]
在iOS8中,我看到了一个跳跃.首先,我看到backgroundViewController然后大约1秒钟左右登录出现.
那么,我怎样才能防止iOS8的这种跳跃?
我正在为我的iOS应用程序创建一个标题栏,我在UIView中创建它.我遇到的唯一问题是"主页按钮".按下主页按钮时,需要转到主页,即ViewController.
但是,它看起来并不[self presentViewController:vc animated:NO completion:NULL];适合UIView.
我该如何解决这个问题?
- (void) createTitlebar {
    CGRect titleBarFrame = CGRectMake(0, 0, 320, 55);
    //Create the home button on the top right of the page. When clicked, it will navigate to the home page of the application
    homeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    homeButton.frame = CGRectMake(275, 10, 40, 40);
    [homeButton setTag:1];
    [homeButton setImage:[UIImage imageNamed:@"homeIcon.png"] forState:UIControlStateNormal];
    [homeButton addTarget:self action:@selector(homeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:homeButton];
}
- (IBAction)homeButtonPressed:(id)sender{
    //Transition to the submit button page
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    ViewController …ios ×8
objective-c ×7
ios8 ×2
swift ×2
uistoryboard ×2
appdelegate ×1
hierarchy ×1
ios10 ×1
ios6 ×1
xcode ×1