I created a storyboard and added the navbar buttons I want to be displayed
But when I simulate my app, this is what I get
I have also tried to programatically add the button using navigationItem.setRightBarButtonItem(), but that doesn't show up either.
However, when I try the same thing using a normal UIViewController, it works
So my question is if this is the behavior of PFQueryTableViewController, and if so, what do I need to do to correct it?
If more details are needed, I'd be happy to provide them - just curious if anyone has run into this problem before.
EDIT
I now have the button showing up on a basic UIViewController using suggestion of #Haidous, but I can't get my PFQueryTableViewController to show up inside it. Here's what I have:
#IBOutlet weak var containerV: UIView!
var favoriteVC:FavoritesViewController = FavoritesViewController(className: "Cat")
override func viewDidLoad() {
super.viewDidLoad()
//?what goes here?
containerV = favoriteVC.view
// Do any additional setup after loading the view.
}
I'm not sure how to make it show up
******EDIT WITH SOLUTION******
I was able to simply create a container in my storyboard and add my view controller like this (in case anyone else runs into the same problem and stumbles on this question)
class WrapperFavoritesViewControllerContainerViewController: UIViewController {
#IBOutlet weak var containerV: UIView!
var favoriteVC:FavoritesViewController = FavoritesViewController(className: "Cat")
override func viewDidLoad() {
super.viewDidLoad()
addChildViewController(favoriteVC)
self.containerV.addSubview(favoriteVC.tableView)
favoriteVC.didMoveToParentViewController(self)
}
I do not know if it is because of the PFQueryTableViewController or not.. but a workaround I found was creating a normal View Controller and setting up your Nav Bar there then placing a container view and connecting it to the PFQueryTableViewController thus PFQueryTableViewController becomes the Child View Controller. Hope I helped :)
Related
I'm trying to combine a Sidemenu and a Tapbarmenu using Xcode's Storyboards.
I took the template from here: https://johncodeos.com/how-to-create-a-side-menu-in-ios-using-swift/
Then, I modified the Home View to have a tap bar :
The first issue that I got is that I lost the SideMenu button :
.
Furthermore, you can notice that the Topbar got really thick and the View is not centered.
To fix the first issue, I tried to create a new cocoapod file for the new navigation controller in order to get the SideMenu button working again :
class MenuViewController: UITabBarController {
#IBOutlet var sideMenuBtn: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
// Menu Button Tint Color
navigationController?.navigationBar.tintColor = .white
sideMenuBtn.target = revealViewController()
sideMenuBtn.action = #selector(revealViewController()?.revealSideMenu)
}
}
I assigned the new class to the Navigation controller but the sideMenuBtn won't appear on the Sidemenu button.
I don't know if my explanations were very clear but don't hesitate to ask me for more information.
Thx,
Julien
I am having a problem when trying to disable button's user interaction of 1 view controller in another view controller.
I have searched similar questions here, but some seems outdated or does not work for me:
How to access an IBOutlet from another class.
My scenario is as follows:
class ViewControllerA() {
#IBOutlet weak var btnFirst: UIButton!
#IBOutlet weak var btnSecond: UIButton!
#IBOutlet weak var btnThird: UIButton!
override func viewDidLoad() {
var vcB = ViewControllerB()
vcB.closure = {
// Meet some condition, want to disable buttons of ViewControllerA here
}
}
}
class ViewControllerB() {
var closure: () -> Void = {}
// Do something with closure here
}
My problem is that i set the breakpoint in the closure and try to use directly IBOulet in closure to disable buttons like:
btnFirst.isUserInteractionEnabled = false
Or try to set a property of ViewControllerA in closure of ViewControllerB and use property observer, whenever this property changes, enable or disable buttons of ViewControllerA.
My problem is that, i can still click the buttons as if it's enable. Sorry, i cannot post the code, please help me!
Thanks
You can post notification from second view controller and add observer for that particular posted notification in first view controller.
In that observer method, you can do your stuff like disabling user interaction for first view controllers' button.
Since you did not post any relevant code, I can only guess what might have happened:
I assume that you are not accessing the btnFirst of the correct viewcontroller. In ViewControllerA.viewDidLoad you are creating an new Instance of ViewControllerB and set the closure. Are you also showing exactly this view controller's view? Or how will the user navigate to B? If you are using storyboard segues, those will create a new B instances and show its view. Now when you execute the closure in A, this will disable the button of the first B, not of the B that is displayed.
But this is still just a guess...
So I have a base class UIViewController called UITabBarTopLevelViewController:
class UITabBarTopLevelViewController: UIViewController {
#IBOutlet weak var uiNavItemTitle: UINavigationItem!
override func viewDidLoad() {
super.viewDidLoad()
uiNavItemTitle.titleView = CoreUtility.LogoForUINavBarGet()
// Do any additional setup after loading the view.
}
I then have two UIViewControllers that inherit from my base class and both look like this, except the second is called MyViewController2:
class MyViewController1: UITabBarTopLevelViewController {
//#IBOutlet weak var uiNavItemTitle: UINavigationItem!
override func viewDidLoad() {
super.viewDidLoad()
//uiNavItemTitle.titleView = CoreUtility.LogoForUINavBarGet()
}
I add a Navigation Bar object to each child UIViewController super view and then I CTRL drag and add a new outlet to each UIViewController child class:
And here is the second CTRL drag outlet:
These are different references, but I can comment out the #IBOutlet weak var uiNavItemTitle: UINavigationItem! in my child classes and reference one time only in the base class UITabBarTopLevelViewController, for both MyViewController1 and MyViewController2.
You can see, when I hover over the outlet circle, in my base class, it highlights both UINavigationItem in the Story Board:
I am surprised this works, its nice for me that it works because I only need to set the uiNavItemTitle.titleView for my logo one time for both views. This is what I want but there seems to be a bit of magic that I can reference multiple outlet references one time in my base class and there is no bugs or crashes.
I currently have no memory leaks or crashes and my app is working just fine and doing exactly as I desire.
Will there be any bugs with this?
Could someone explain how this is working?
Is the fact that this works, not surprising to experienced Swift developers?
That's how subclass exactly works.
You placed a UINavigationItem in the base class UITabBarTopLevelViewController through
uiNavItemTitle.titleView = CoreUtility.LogoForUINavBarGet()
Also, MyViewController1 and MyViewController2 inherit from the base class UITabBarTopLevelViewController. That's say these child viewControllers both have a UINavigationItem which inherit from their UITabBarTopLevelViewController.
This is not a bug, on the other hand, more like a topic about design pattern though. You could place all the base stuff into a base class, inherit from those classes and implement the specific detail within the child class.
HTH.
this is my first time doing ios project and everytime i try to run this app , its stuck on the white screen . Any ideas or solutions to this problem would be appreciated . I have no idea whether its the code's fault or the simulator.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var mySwitch: UISwitch!
#IBOutlet var Answer: UILabel!
#IBOutlet var tempInput: UITextField!
//aqnswer value
#IBAction func switchPressed(sender: AnyObject)
{
if ( mySwitch.on ) {
self.Answer.text = "cel to fah"
}
else
{
self.Answer.text = "fah to cel"
}
}
//textfield value
#IBAction func calculate(sender: AnyObject)
{
//get user input
// value = celcius
var Value:Int = tempInput.text.toInt()!
var toFah :Int = ( 32 + Value * 9 ) / 5
//to celcius
var toCel: Int = (Value-32) * 5 / 9
if (mySwitch.on)
{
self.Answer.text = toFah.description
}
else {
self.Answer.text = toCel.description
}
// println(fah)
// Answer.text = fah.description
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Ok, there could be a number of things that are wrong here.
1) If you are using storyboard to design the UI. Check if Viewcontroller has been set as the initial viewcontroller. You should see an arrow thats pointing at the first view controller.
2) Put in some print messages in viewDidLoad, viewWillAppear and viewDidAppear functions. This should tell you if the view controller is getting loaded.
3) Another common mistake : And this probably is what is happening. I see you have a button, right click on the button in the storyboard and see what all methods/outlets it is connected to. Some times, when you make a connection from storyboard to code. Using Control + Drag. And if you later delete the code. Storyboard still retains the link to the code.
At launch it tries to connect to the code and if it doesnt find the outlet or IBaction it causes a crash.
Terrible controller naming aside, it seems like your storyboard has no entry scene (and your controller is probably not referenced there, if you create one). Xcode should give you a warning on the first problem, though.
That white screen is the default launch screen; it will go away as soon as the root view controller gets installed by the storyboard (asuming you use that).
In Interface Builder, are you sure that ViewController is the class associated with the starting controller ?
Can we have a screenshot of the ViewController in Interface Builder? (because from the problem explanation i understand you set up a view in Interface Builder with a text field, a button and a switch button
I believe 99% of the time this is the code's fault...
I have just recently started learning Swift and iOS development and I am trying to get Google Street View working on a Single View Application. So basically I was thinking to have a ViewController that has a view and inside the view I will have the StreetView view and a Button.
Following Google's tutorial: https://developers.google.com/maps/documentation/ios/streetview I can get everything working. It works when I do this:
self.view = panoView
Now, I am trying to achieve what I mentioned above with the following code:
class ViewController: UIViewController, GMSPanoramaViewDelegate{
#IBOutlet weak var panoramaView: GMSPanoramaView!
override func viewDidLoad() {
super.viewDidLoad()
var panoView = GMSPanoramaView(frame: CGRectZero)
self.panoramaView.addSubview(panoView)
self.panoramaView = panoView
self.panoramaView.delegate = self
panoView.moveNearCoordinate(CLLocationCoordinate2DMake(position.latitude, position.longitude))
}
}
And what I have in the storyboard is the following:
The only thing I can see is the refresh button.
I have also tried not setting the view as a GMSPanoramaView but only as a UIView, but that also didnt work
Can anyone point me to the right direction, please? Ultimately what I want is the StreetView covering all my screen and I want some buttons and some views on top of it.
I am using Xcode 6.1
Thanks
EDIT:
I added the function and can see the ID being printed out
func panoramaView(view: GMSPanoramaView!, didMoveToPanorama panorama: GMSPanorama!) {
println(panorama.panoramaID)
}
StreetView still empty