I have an application that has following schema:
Login -> Tab Bar ->
UINavigationController -> Tab1ViewController
UISplitViewController -> UINavigationController -> MasterViewController/DetailViewController
UINavigationController -> Tab3ViewController
Then I implement in my DetailViewController
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
but it never get called.
I also have put the splitview delegate in my detail:
#interface DetailViewController : UITableViewController
<UISplitViewControllerDelegate>
Is there anything I'm missing?
You're missing multiple things.
One, in order to quickly solve your problem, write:
splitViewController.delegate = self;
Two, note that it does not matter whether or not you're conforming to the <UISplitViewControllerDelegate> protocol. It's just a hint for the compiler - it does not make the view controller magically know which object is supposed to be its delegate...
Three, as a sidenote: this has absolutely nothing to do with Xcode.
Related
there's a lot of code in here but please be patient I will try to explain my question
so i am trying to convert Apple's AvDepthCapture project which is in UIKit as a SwiftUI project, so i copied all the supporting files, i will attach the image for the same below, the shaders folder contain the metal files for applying filters
so I created a class same as the cameraviewcontroller and added all the properties as follows -
class CameraViewController: UIViewController, AVCapturePhotoCaptureDelegate, AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureDepthDataOutputDelegate, AVCaptureDataOutputSynchronizerDelegate, ObservableObject {
private var previewView: PreviewMetalView!
}
now when i run my app on my device it asks for camera permission but then shows a white screen instead of opening the camera and the PreviewMetalView file that i copied earlier directly from the original UIKit project,
the declaration is causing error
private var previewView: PreviewMetalView!
this line, it quits my app and says unexpectedly found nil when unwrapping an optional value but the code is the same as that of the UIKit project and UIKit project works perfectly fine on my device then why is it throwing this error!?, please help i can provide both the UIKit project and my SwiftUI project file if you want to see i really can't figure it out
there's a lot of code but this specific line is throwing error, I declared a type of PreviewMetalView but now PreviewMetalView has an initialiser which takes in a type NSCoder so what should I write there ??
like I would be declaring my variable as
var previewView = PreviewMetalView(coder: NSCoder)
what to put in place of NSCoder ?
when I opened the original UIKit project the previewView is defined as an IBOutlet to a Container View which is then linked to the CameraViewController but I cannot find where is it initialised please help!
I'm implementing Google Maps in my project, because MKLocalSearch doesn't have a complete list of restaurants/bars. I'm following Google's documentation. I believe I've uncovered an issue and seek advice on how to solve.
The fist step is variable declaration at the class level:
var locationManager = CLLocationManager()
var currentLocation: CLLocation?
var mapView: GMSMapView!
var placesClient: GMSPlacesClient!
var zoomLevel: Float = 15.0
After following the remaining instructions, my program keeps failing on the mapView line:
let camera = GMSCameraPosition.camera(withLatitude: defaultLocation.coordinate.latitude,
longitude: defaultLocation.coordinate.longitude,
zoom: zoomLevel)
mapView = GMSMapView.map(withFrame: view.bounds, camera: camera) //Fails here!
The error message in the debugger is: Fatal error: Unexpectedly found Nil while unwrapping optional value.
So the question is why does the Google documentation declare the mapView variable the way it does? Don't all variables that ARE NOT optional have to initialize with a value? Should I declare the variable as Optional? Seems odd to me that Google Documentation would be incorrect.
Thanks.
By declaring an optional with ! you are telling the compiler whenever I access this optional it will have a value. It means you don't have to stick ! at the end everytime you use it. But it does mean if you haven't set the optional to have a value you will get an error when you access it.
An example of using one would a class member of a UIViewController that you setup in viewDidLoad(). You aren't required to setup a separate init() function for the view controller to initialise the variable but you can pretty much guarantee the entry point for your code is viewDidLoad() and any subsequent code run will have a valid version of this class member.
Search for Implicitly Unwrapped Optionals for more details
you should take optional mapView when there is possibility of having mapView or not. You should always take like this
let mapView = GMSMapView(frame: self.view.bounds)
I do have a strange issue in using the reorder feature in my app's UICollectionView. We have a custom layout which is implemented to show a decoration view. The collection view uses a flow based layout. When I move the first cell from its position to last cell position for reordering of the cells, the app crashes before it calls the collection view delegate's collectionView(moveItemAt: to) method.
Attached the stack trace of this issue. You can see that crash is happening in the bridging between NSIndexPath and IndexPath. I am not sure why it is happening inside UIKit. Searching for this issue found that it appears to be bug inside UIKIt which got introduced in Swift 3.0. I tested my old build which was built before swift 3.0 migration and it works without any crashes.
Can someone tell me how can I fix this issue?
Related bugs links
UICollectionView broken after Swift 3 migration?
https://bugs.swift.org/browse/SR-2103
https://bugs.swift.org/browse/SR-2417
func handleLongGesture(_ gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
case UIGestureRecognizerState.began:
if let movingPageIndexPath = collectionView.indexPathForItem(at: gesture.location(in: collectionView)) {
collectionView.beginInteractiveMovementForItem(at: movingPageIndexPath)
}
case UIGestureRecognizerState.changed:
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: collectionView))
case UIGestureRecognizerState.ended:
collectionView.endInteractiveMovement()
default:
collectionView.cancelInteractiveMovement()
}
}
Question is as simple as the tip of the question.
banner is working in test mode in device.(seems like so: "You re connected to the iAd Network").
declared -didFailToReceiveAdWithError, -bannerViewDidLoadAd and -bannerViewActionShouldBegin.
and ADBannverView1.delegate assigned to self (is a cocos2d CCLayer)
but these methods never called. I drop some breakpoints that never runs into.
have you any idea ?
Question 2: what is the difference between these property definations ? should I use weak, assign ? or IBOutlet is a necessarry ?I tried all 3 combination and all worked.
#property(nonatomic,retain) ADBannerView *iAdView;
#property(nonatomic,retain) IBOutlet ADBannerView *iAdView;
#property(nonatomic,assign) ADBannerView *iAdView;
For me the problem was that I also had this line in my code self.canDisplayBannerAds=YES;
After I removed it delegate method were called properly.
I'm trying to do some saving/loading in my AppDelegate, for which I need my enemy and hero sprites. I'm using cocos2d. Here's the method that's getting the warning.
-(void)applicationDidFinishLaunchingWithOptions:(UIApplication *)application {
NSMutableArray *loadedMoles = [DataBase loadDocs];
NSMutableArray *loadedBunnies = [DataBase loadDocs];
UINavigationController *navigationController;
viewController = (RootViewController *) [navigationController.viewControllers objectAtIndex:0];
viewController.mole = loadedMoles; //error
viewController.bunny = loadedBunnies; //error
}
Even though this is the AppDelegate, I've imported both classes, and I'm still getting the errors.
Relevant portion of comments
Jonathan
Given that the problem is not just . vs ->, the other main option, then, is that your viewController does contain any moles or bunnies.
Joe
I'm using the tutorial at http://www.raywenderlich.com/1914/how-to-save-your-app-data-with-nscoding-and-nsfilemanager. (There is code there to download.)
Doing:
viewController->mole = loadedMoles;
says
'struct RootViewController' has no member named 'mole'
How do I add it to viewController?
Although in the tutorial they use
NSMutableArray *loadedBugs = [ScaryBugDatabase loadScaryBugDocs];
RootViewController *rootController = (RootViewController *)
[navigationController.viewControllers objectAtIndex:0];
rootController.bugs = loadedBugs;
Jonathan
In the downloaded code (ScaryBugs3/Classes/rootViewController.h), the demo has:
#class EditBugViewController;
#interface RootViewController : UITableViewController {
NSMutableArray *_bugs;
EditBugViewController *_editBugViewController;
}
#property (retain) NSMutableArray *bugs;
#property (retain) EditBugViewController *editBugViewController;
#end
Does your equivalent have 'mole' and 'bunny' properly defined? If so, I'm at a loss to help you much further.
Joe
I never downloaded the source code, so I didn't see any of that. Thanks, I was wondering if he might have bugs as an array instead of a bug sprite.
Not very relevant portion of answer
In regular C or C++ with GCC, the error message normally occurs when either:
You use structptr->member and you should use structvar.member, or
You use structvar.member and you should use structptr->member.
Objective-C is close enough to C at this juncture that you probably need to review your use of . vs -> notation, I believe.
Now that your code is legible, the lines giving the error are:
viewController.mole = loadedMoles; //error
viewController.bunny = loadedBunnies; //error
You probably need to use viewController->mole and viewController->bunny instead? (I'm not sure of that, but to the extent Objective-C is a superset of C, that would be a necessary change. However, it could be that Objective-C does away with the need to distinguish between . and ->.)
At the link you gave is used RootViewController class and you are trying to use UINavigationController that simply does not have such properties as mole and bunny as #Jonathan said
I also had the error 'Request for member "options" in something not a structure or union' come up.
#interface Dialog : NSManagedObject {}
#property (nonatomic, retain) NSSet* options;
#implementation Dialog
#dynamic options;
Where I simply forgot to import "Dialog.h" in the class that was trying to access this instance.