I am trying to implement the ELCImagePickerController, but when I try to present the picker, just a black screen shows up with a navigation bar at the top. I moved all files(also the xib) into my project :/ Is this a problem because of swift/ios8 ?
var imagePicker:ELCImagePickerController = ELCImagePickerController();
self.presentModalViewController(imagePicker, animated: true);
That's because you are just calling the init method instead of the proper initImagePicker that is expected to be used (See the source here).
If you instantiate in like this it works:
var picker = ELCImagePickerController(imagePicker: ())
Note that the name is weird because of the automatic conversion that Xcode does for you of the Objective-C method by removing the init part of the name.
Also note that you don't need to specify that picker is of type ELCImagePickerController because Swift infers it automatically.
Hope this helps :)
Related
I want to update the image when the user clicks something in the application but I can't get it to work.
The status item with the menu is defined in the AppDelegate. I am trying to update the image in the ViewController with this piece of code which I think should work:
AppDelegate().statusItem.button?.image = NSImage(named:NSImage.Name("icon-orange"))
No errors are showing up, but turns out it still doesn't work, so is it possible to change the image or am I doing something wrong?
AppDelegate() creates a brand new instance which is not the delegate class in Interface Builder.
You need the real reference:
(NSApp.delegate as! AppDelegate).statusItem.button?.image = NSImage(named:NSImage.Name("icon-orange"))
I am developing a Walkthrough screen where I have added 3 instruction images which help the users to work with the application. The problem occurs, when I first launch the app I see only the labels with the "instruction tekst" , but below this label the user should also see the images. Maybe I am doing something wrong, attached I uploaded a picture of the error:
And here I upload the picture of the code I have used to transfer these picture to the TutorialPageContentHolderViewController:
I would be very thankful if you see my mistake, because I have been struggling with that the whole day.
I guess the imageFileName variable in your first image is nil when you use it in
myImageView.image = UIImage(named: imageFileName)
When you assign it a value in the second screenshot it could be too late, as viewdidLoad is loaded before that. You could check if this is true by manually assigning a valid value to imageFileName before using it and see if it works.
One simple way to fix it would be to add an initialiser to the view controller class, pass the filename as a parameter and store the filename in a local variable until you use it in viewDidLoad.
A second way would be to add a method to the page view controller as below (and remove the corresponding line from viewDidLoad):
func prepare(with filename:String) {
myImageView.image = UIImage(named: filename)
}
and call it from the pageTutorialAtIndex method in your main view controller.
The unwind segue to the menu view is no longer working on XCode 7 with iOS 9.
The only way I got it to "work" is by changing the type of segue in the storyboard to an ECSlidingSegue from the default UIStoryboardSegue. the ability to change this in the storyboard for unwind segues seems to be new to XCode 7. When changed to the ECSlidingSegue it only shows the menu view itself and the view it was supposed to shift to the right (but still keep on the screen) disappears. All other segues seem to be working and I can confirm that all was working correctly in iOS 8 and XCode 6.
Any ideas why this would not be working?
It looks like ECSlidingViewController hasn't been updated for a year now.
In some of my apps I am using MMDrawerController which seems to do exactly the same and I can confirm that it works with iOS 9. And it is updated on a more regular basis. If you are interested in trying it you can check it here
No, but until it's fixed, you can show the menu from code:
- (IBAction)menuButtonTap
{
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.view.window.rootViewController;
[slidingViewController anchorTopViewToRightAnimated:YES];
}
#IBAction func menuButtonTapped(sender: AnyObject) {
let slidingViewController = self.view.window!.rootViewController as? ECSlidingViewController
slidingViewController?.anchorTopViewToRightAnimated(true)
}
I managed to get it working correctly using swift by attaching each of the menu buttons in each of the view controllers to an IBAction function. I then put the code as it is above into each of these IBAction functions. The code uses the current instance of ECSlidingViewController (the current view) and then calls anchorTopViewToRightAnimated in order to correctly assign the current view that is being pulled to the right.
I am trying to instantiate a ViewController defined in MainStoryBoard.storyboard using the code snippet shown in the pic below. I also assigned an identifier to the controller but app crashed with the error shown in pic saying "Storyboard doesn't contain a controller with identifier masterViewController" although you can clearly see in pic that its there.
Any help will be appreciated.
Just so you know, following solution didn't work for me: Crash with instantiateViewControllerWithIdentifier
Below is the snapshot that confirms that the storyboard object is same that is retrieved from viewcontroller and used to instantiateViewControllerWithIdentifer:.
SITUATION DESCRIPTION: I am trying to develop a custom SplitViewController (subclassed from UIViewController). This UIViewController is purely programmatic i.e. not based on IBInterface layout. However for its children i.e MasterViewController and DetailViewController I have made layouts in IBInterface. Now I am retrieving a UIStoryboard object in SplitViewController (purely programatic one) and passing it to a utility class shown here in the first pic that uses it to instantiate MasterViewController based on a layout in the Storyboard.
Hm, looks like if should work.
Try this:
Clean project and rebuild
Check if storyboard contains an instance of the correct storyboard
Fix by shaffooo (from comments below)
I rebuilt my storyboard and it fixed the issue I was having.
try to write the same name of your ViewController class into 'StoryBoard ID' in IB. Then edit the argument of your instantiateViewControllerWithIdentifier method with same string:
yourVCName *startingViewController = (yourVCName *)[self.storyboard instantiateViewControllerWithIdentifier:#"yourVCName"];
I'm debugging an iphone app and I'm seeing something I don't understand fully.
Based on user's selection, a UIView is being shown or hidden. Current code shows or hides the view with [view setHidden:NO] and [view setHidden:YES]. This doesn't work: visually it's as if these statements are simply ignored. However when I changed these to view.hidden = NO and view.hidden = YES respectively, everything is working as expected.
I was thinking that the two syntaxes are equivalent, but apparently not. For all other attributes (text, font, etc.), both work identically, so what's so special about hidden?
EDIT: Here's the copy/paste of some of my code. I'm working in XCode 4.3 with iPhone simulator 5.0
Here's one example from my project.
IBOutlet UIView *panel; //Connected in interface builder
===========
- (void)makePanelVisible:(BOOL)visible
{
[panel setHidden:!visible]; //this does not work
panel.hidden = !visible; //this does work correctly.
}
Sets whether the view is hidden.
- (void)setHidden:(BOOL)flag
Returns whether the receiver is marked as hidden.
- (BOOL)isHidden
hidden=YES; is identical to setHidden:YES; The difference is, you are turning hidden to YES right away Whereas sethidden view disappears from its window and does not receive input events because it is set to be hidden. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual.
Thinking back about this, I remember running into the same issue almost 3 years ago, when iPhone 3 (not even 3G) was all the rage. I'm not sure why this happens, but it does - so I just deal with it by setting the property using the "dot" notation. I guess, this is one of those "don't fix it if it ain't broken" things (ok, it is sort of broken, but there's an easy way around it, so I'm using it).
hidden is a property of UIView. When you wrote [panel setHidden:YES], you try to call the method setHidden that should set the property hidden. It doesn't work because the method doesn't exist in the UIView : https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816
I always set the property by writing "view.hidden = x".
I hope it will help you