I have a problem with my iconMenu it doesn't work, I can only slide to open my menu, I have this error only I change page from my first page ("Accueil") instead of using my slide out menu. Yes because I have a slide out menu and links on my first page, like that:
So when I use links of my first view, my iconMenu is like disabled, it's because here:
#IBAction func menuNosOffresTapped(sender: AnyObject) {
delegate?.toggleLeftPanel!()
}
My app can't go at the function toggleLeftPanel here: Call a function of an another class (protocol) someone told me that the problem could came from my delegate.
I did some test, I lost my delegate when I use first page links and when I use my Slide out menu.
App is here: https://github.com/Vkt0r/SlideOutSideBarTest
So I think to get access to toggleLeftPanel, I have to get my delegate.
the problem is your NosOffresViewController is missing the menuTapped action.
Related
I have a webview on view controller that load a page consist of list of item.
If I click on each item, I want to navigate into spesific view controller and bypass an id from item's link.
Right now I have no clue how to do this. Is this even possible?
Any help would be appreciated. Thank you.
Yes, this is entirely possible. You need to use a URL Scheme to communicate from JavaScript to native code.
A URL Scheme allows you to pass data from JavaScript to native code like this:
window.location = 'yoururlscheme://somehost?greeting=hello'
You receive this event using UIWebViewDelegate, where you can fire a segue, or whatever you want.
See this answer for details: https://stackoverflow.com/a/36144481/1305067
I am newbie in iOS with swift. What I need to do right now is that I have a textfield for user to enter his/er username. And once he clicks the other textfields, say password section, the application will automatically check whether this name exists or not and display a "V" or "X" image in a imageView. But I don't know how to do that or what method or action I should deal with. In Android, I could detect the focus of that textfield.Once the textfield loses the focus and if the text isn't empty, I can retrieve the text and request to my server to verify whether it exists or not. In iOS, I'm totally confused how to detect this, and is this related with first responder? Thx for advice in advance!
Use UITextFieldDelegates.
class XXX : YOURCONTROLLER, UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.PASSCODE.delegate = self
}
func textFieldDidEndEditing(textField: UITextField) {
if textField == PASSCODE {
//update stuffs
}
}
}
On iOS, you generally create the interface in Interface Builder (a graphical tool you can use to place UI elements on screen and define many of their properties), and then you link them to your code using what's called IBOutlets/IBActions.
The code your link those elements to is often the view controller ; the view controller is the object that is responsible for managing a view and the events it receives.
To make an IBOutlet, go to your interface builder file (1), select the view controller you are interested by (2, for you it will be the one it which your form is present) open the assistant editor (3), the assistant editor should show to code corresponding to your view controller. Then control drag to the inside of your view controller class definition (4).
Once you do that there will be a little "popup" asking you wether you want an outlet or an action (5), if you just want a reference to the given UI object, then select an outlet.
If the object does an action (for example a button) and you want a method to be called when this action occurs, then you would choose action.
From there this should be pretty straightforward, what I would do would be to make an outlet to the textfield containing the password, and an action for the "Send/Connect" button, whether the method linked to this event would be called, I would check if the password is right or wrong.
EDIT : Maybe I added to much details and you already know a lot about what I told you, but when beginning, those things aren't always that much easy.
I have a simple app in Swift with just a few views:
A UIWebView
some TableViews
and another view with some data I download from my server
It all works well until when using the app I press the home button, leave there for a while then the iPad goes on sleep mode. A few days later I tap on the app icon and it won't start:
first tap on the icon will select the icon (goes a little darker) and deselect it a few seconds later
second tap will launch the LaunchScreen and crash a few seconds later
double tap the home button and quit the app will sometimes work
I'm just wondering if there is something I need to set on my code to handle idle/long periods of inactivity in something like viewWillDisappear or other methods?
If so I already have this in all my controllers:
override func viewWillDisappear(animated: Bool) {
timer.invalidate()
webView.removeFromSuperview()
}
Maybe I need to call super. in there too? or something else I'm missing?
You should definitely call super in your viewWillDisappear(animated:) method. See UIViewController Class Reference documentation. Also you might want to confirm why you are removing your webView from the view controller's hierarchy.
Discussion
This method is called in response to a view being removed
from a view hierarchy. This method is called before the view is
actually removed and before any animations are configured.
Subclasses can override this method and use it to commit editing
changes, resign the first responder status of the view, or perform
other relevant tasks. For example, you might use this method to revert
changes to the orientation or style of the status bar that were made
in the viewDidDisappear: method when the view was first presented. If
you override this method, you must call super at some point in your
implementation.
You probably have some null pointer exception and crash. Maybe you are calling some variable that is not set (and checked if not null).
Try disabling app funcionality (like downloading, storing and using data from server) and see where you app starts working normal again and then procede from there.
Sorry for vague answer but withouth code and maybe some log it is really hard to give specific answer.
And NO, you dont have to do anything special to handle idle/long periods of inactivity.
I am working in swift. I have a protocol defined that has a function called reload. I have a home class which is a tableviewcontroller where I extend the protocol and implement the reload function. I have another class where there is a button. On this click of the button I set the delegate and the reload function is called. Until this step it works fine. Now in the reload function i want to refresh the home page, so i tried
tableview.reload()
this is not working and the app is crashing, then i tried calling
viewDidLoad()
this is also not refreshing the page. I dont want to use NSNotification
what am i doing wrong?
Can anybody please help
Thanks in advance
Are you sure your UITableView data source delegate methods are working properly? You should look up viewDidLoad() and viewWillLoad(), etc... in the UIViewController reference page (Apple doc). If you're serious about app development I recommend at the very least making the time to spend 15 - 30 minutes each looking at the UIViewController and UIView pages to familiarize yourself with them, since you'll be using them all the time. You should know basically how they work. Also check out CALayers in UIViews. Then you'll be better established to write really nice apps.
you are setting a delegate on button touchup inside event, please check whether you are setting a delegate to your Home class .
I assume your mean tableview.reloadData() which is the correct method to call for reloading your tableview.
You shall not call viewDidLoad by yourself.
Thank you for viewing this page.
I have downloaded the following from GH: https://github.com/watsonbox/ios_google_places_autocomplete
It uses a nib file to initiate a autocomplete feature within a ViewController (in the Main Storyboard.
Issues
The following issues are hindering my progress;
I am unable to close the nib view using the X (or Stop button). The
nib loads via ViewDidLoad, therefore every time it dismisses itself,
it will be shown again. I have attempted to do the following but it
does not work.
When any cell is selected, I am unable to go back to the ViewController I originally navigated from. (same as point 1,
however should happen once I select any of the cells).
extension LocoSearch: GooglePlacesAutocompleteDelegate {
func placeSelected(place: Place) {
println(place.description)
println(place.id)
var locoResult = PFUser.currentUser()
locoResult["placeDesc"] = place.description
locoResult["placeId"] = place.id
locoResult.pin()
self.performSegueWithIdentifier("locoDone", sender: self)
}
func placeViewClosed() {
dismissViewControllerAnimated(true, completion: {
self.performSegueWithIdentifier("locoDone", sender: self)
})
To stop the autocomplete controller from loading every time the view loads, either remove it from viewDidLoad (and put it in a button click handler, for example), or if that's really where it belongs then perhaps use a variable stored property to store the currently selected Place and only show the autocomplete controller if none exists.
placeSelected is the correct callback for handling selections. Perhaps you should dismiss the autocomplete view before performing the segue as you do in your close handler? Please link a Github project with this issue if you really can't get it working.