Why doesn't button state remain? - swift2

I have the following code:
#IBAction func mybuttonclick(sender: UIButton) {
if(sender.titleLabel?.text == "Start"){
sender.titleLabel?.text = "Change"
}
else {
sender.titleLabel?.text = "Start"
}
}
When I click the button, I see "Change" flash and then it goes back to "Start". This is a simple new test app. The above is the only code I have in the app. Why does the button text change back to "Start" instead of remaining on "Change"?

Its very hard to answer this question without more information, but I think it's possible you have the action bound twice in Interface Builder. Where the action is being fired twice each time you hit the button. Another possibility is you have the button inside a table or collection view cell where the cell is being reused and replacing your previously edited button.

Related

swift 3 check the row where the button was pressed

i have a outline view with a custom cell.
all works fine but i need to know, if a button was pressed, in which row number the that button is.
how can i get this row number ?
You could wire up your button's action to an IBAction in your view controller (or whatever knows about the outline view) and call row(for:) on the outline view:
#IBAction func buttonClicked(_ sender: NSButton) {
print("button row:", outlineView.row(for: sender))
}
Straight from the docs:
This method is typically called in the action method for an NSButton
(or NSControl) to find out what row (and column) the action should be
performed on.

Can we override NAVIGATION BACK BUTTON press in Xamarin.forms?

Can we override navigation back button pressed in Xamarin.forms?
I have one navigation back button and the one save button in navigation bar.Save button hits the web service and saves in asynchronous way. While saving although i used progressing bar, navigation back button can be pressed and hence the app crashes due to index out of range exception on navigation stack.I tried using OnDisappearing() , did not work. I wanna cancel the PopUpAsync(),if the save is not done completely, but failed to achieve that. Is there any solution for this scenario? Can we override the navigation back button press event using any custom renderer ?
For controlling the back button to do what I want, I used this method in Xamarin:
public override bool OnKeyDown(Keycode HWkeyCode, KeyEvent e)
{
if (HWkeyCode == Keycode.Back)
{
StartActivity(typeof(FrontPageActivity));
return true;
}
return false;
}

Swift 2 Is it possible to add a web link to an annotation callout?

I'm able to create pin's with their popup's as well as the info-light button to the right. And when tapped, the info button pops up an alert with some text and an "ok" button at the bottom. Is it now possible to add a link at the bottom of the text that will direct the user to a URL, saw wikkipedia for example in safari?
I've used the following called function to succesfully do so with a regular button in the mapview, but I can't figure out how to implement it the way I've stated above
#IBAction func webLink(sender: AnyObject) {
if let url = NSURL(string: "http://www.wikipedia.com") {
UIApplication.sharedApplication().openURL(url)
}
}

I need assistance with xcode buttons

So I'm trying to make an event happen with buttons in xcode, and it's working fine, and executing the way I want it to, but now I want a different section of code to run if the button is not being pushed. I don't know how to test for if a button is NOT being pushed. Any ideas?
While a NSButton is pressed its state is non-zero.
if (myButton.state) {
// My button is pushed!
}
Here's something that can help you. Define a var ,notPushed whose value can be checked to see if button is called or not.
var notPushed:Bool=true
#IBAction func buttonPressed(sender:UIButton)
{
//....
notPushed=false
}
To check wether the button is pressed :
if notPushed==true{
//...
} else {
//...
}
Link your button to the buttonPressed.

Done Bar Button isn't dismissing view controller

Can anybody please tell me why my 'Done' bar button isn't dimissing my view i'm trying to edit the data from the table view?Here is the link of my code:
https://www.dropbox.com/s/gylo67z2n00yc9i/TableView.zip?dl=0
I want to know the reason.I can't figure out what i have missed out.
1.add following method in checkListViewController.
-(IBAction)unwindTocheckListViewController:(UIStoryboardSegue *)segue {
}
select Storyboard and select Add Item View Controller Scene.
Press ctrl on your Mac, select Done button and drag(pressing ctrl) to Exit.
A pop up opens up with above method name. Select it.
Repeat same for Cancel button.
You done!!!
Read upon UnwindToSegue. where your codes goes etc.
Hope this helps.
-(IBAction)unwindTocheckListViewController:(UIStoryboardSegue *)segue
{
SourceViewController *source = [segue sourceViewController];
/*
values of properties declared in .h file of your source ViewController
(called rightly SourceViewController) can be passed to
viewController you coming back to(Unwinding to).
*/
}
here source is your View controller where Done button is, this helps to bring your input from source to destination view controller.

Resources