UIButton text not staying changing

I am developing a simple iPhone app in Swift

I have a customUITableViewCell. In the cell I have a normal UIButton with text of "Hello World".

In my code for the custom cell, I have the following function:

@IBAction func buttonAction(sender: AnyObject) { if likeButton.titleLabel?.text == "Hello World" { likeButton.titleLabel?.text = "Hi!" } }

When I tap theUIButton, the text of theUIButton changes to "Hi!" for just a split second! And then it quickly changes back to "Hello World"...is there any way to fix that?

Why is it doing that?

-------------Problems Reply------------

Use UIButtons's setTitle: forState: rather than setting text on titleLabel of button. For Instance-

Initial set up

likeButton.setTitle("Hello World", forState: UIControlState.Normal)

On click set up-

@IBAction func buttonAction(sender: AnyObject) {

if likeButton.titleLabel?.text == "Hello World" {
likeButton.setTitle("Hi!", forState: UIControlState.Normal)


likeButton.setTitle("my text here", forState: UIControlState.Normal)

Use this code

Do Something like this :

@IBAction func buttonAction(sender: AnyObject) {

likeButton.setTitle("Hi!", forState: UIControlState.Normal)


it works here, hope also work there, set your default value-

yourButton.setTitle("Hello", forState: UIControlState.Normal)

when you tapped your button set this

@IBAction func buttonAction(sender: AnyObject) {

if yourButton.titleLabel?.text == "Hello " {
yourButton.setTitle("Max", forState: UIControlState.Normal)


Category:ios Views:1 Time:2018-08-09

Related post

  • Changes to Compatability Mode will not stay changed 2012-09-05

    I am trying to turn off Compatability Mode for a game program, but no matter what I try I cannot make the changes stay. I believe I am the administrator, but not sure. Is there some way to tell if I am logged in as the admin? I am using XP with the m

  • $().text(); Not Getting Changed Value 2011-11-17

    So I'm working on an app where I need what the user enters to be transferred to another element after being processed. However when I try to grab the .text() value of the <textarea>, it simply returns whatever the value was when the page first

  • Changes not staying changed 2013-02-16

    I am having this problem on 3 of 3 computers running win 7 (two rc and 1 final). When I make a change - example turning off norton firewall or Adobe flash updater and restart - all changes are lost and program goes back to original configuration. I a

  • Why does not work changing UIButton text via dot syntax? 2011-08-09

    Is it possible to change UIButton title label text via dot syntax? The text is not changing if I do it via dot syntax: self.myButton.titleLabel.text = [NSString stringWithString:@"Nop"]; But this one does: [self.myButton setTitle: @"Yep" forState: UI

  • UILabel text not changing? 2012-01-26

    Unable to change text in lMenu_time (this is a UILabel) after it was initially set. The call back is executed, I tested this, but the text won't change. ?? I am passing around the pointer and making adjustments to the UILabel. ?? lMenu_time and numer

  • Cleartype Text does not stay on. 2012-03-15

    I always have to turn on Cleartype text for my two LCDs when the computer goes to sleep, hibernate, and on/off. Why will this setting not stay selected. Why is there not more options to allow this function to continue working. This is incredibly anno

  • My screen text will not stay at the same setting made in Control Panel... 2015-01-24

    My screen Text will not stay at the same setting made in Control Panel. I have also tried to set it using Regedit, but it changes from Decimal to Hexadecimal setting. The desk top has not been effected by this change, but the screen pages change to d

  • Javascript Hide Input Field based on Select change TEXT not VALUE 2011-03-02

    I have a drop down list (select) populated from SQL. This is dynamic so can change at any time. I need to hide an input field based on the selected items TEXT not its Value. Here is my current code: <select name='addEventEventName' style="width:18

  • UIButton does not diplay text set with [UIButtonname setTitle] 2011-10-04

    For the following code (where the UIButton is not connected to an IBOutlet): UIImage *defaultButton = [UIImage imageNamed:@"StandardButton.png"]; PlayButton = [[UIButton alloc] initWithFrame:CGRectMake(250, 50, 220, 50)]; [PlayButton setImage:default

  • Xcode text not changing color when syntax is correct 2011-10-24

    I have one xcode project that for some reason, if the syntax is correct the color of the text isn't changed accordingly. The only text that is colored are words like int, BOOL, double, self, return, etc. Parameters like image->height or object typ

  • How can i do to change value id if i keyup input text not match? 2012-01-13

    How can i do to change value id if i keyup input text not match ? Here's the code : <script src="jquery-1.4.js"></script> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script type="text/javascript" src

  • after change dpi for bigger size text not able to change the dpi because cannot scroll down to click on ok. 2012-01-29

    after changing the dpi for bigger size of text and wanting to change the dpi to increase the text not able to scroll to the bottom of the document to click on ok, and that 's needed to change the dpi. --------------Solutions------------- Hi dorusje,

  • text not visible after moving UIButtons 2012-03-11

    float newY = 0; CGRect buttonFrame; for(int i=1; i<=countTabItems;i++){ id item = [self viewWithTag:i]; if([item isKindOfClass:[UIButton class]]){ UIButton *button = item; [item release]; NSLog(@"got %@", button.titleLabel.text); buttonFrame = but

  • Hidden text does not stay hidden 2012-08-28

    Folks, I cannot get hidden text to stay hidden. If I mark text as hidden, and do File>Options>Display and clear Hidden Text and Always show formatting Marks, the text vanishes. After I re-start word, the hidden text is visible again. Note: I am

  • Outlook 2010 Condional Formating changes not staying in place 2012-09-07

    Just wondering if anyone would know the solution to why my conditional formatting changes are not staying in place? I'll make some font colour/size rules for emails from certain people and the changes will stay in place for a bit and then all of sudd

  • Selected text will not stay selected 2014-06-04

    Selected text will not stay selected - This occurs in All Office 2010 programs and IE about 90% of the time --- Click at start of copy - shift - click at end does the same thing. This drives me crazy --- --------------Solutions------------- Are there

  • How do I keep JUST the blackline in a document and NOT the changed text? 2014-08-15

    I write technical manuals which are updated periodically. Using Word 2000 we have previously used a blackline in the margin to denote changed lines of text, which allows readers to quickly identify the changed lines or paragraphs without reading thro

  • UITextField text not changing on the UI 2012-01-24

    Once the code bellow is executed, the textfield's text doesn't change in the UI to "Fly" but the second NSLog does print "TextField: Fly" as it should. @property (strong, nonatomic) IBOutlet UITextField *typeTextField; .... UITableViewCell* cell = [s

  • Table Columns not staying the same width 2011-02-14

    I'm working on a Calendar using tables and divs. The columns are not staying the width I set them in the CSS file. They should all be 20pxs; The Row they are in width is set to 100% and the table width is set to 100%. The Div that holds everything wi

  • Ajax.ActionLink does not stay on same page 2011-11-25

    This is so simple but I cannot get it to work. I have a page with a link and I am doing an ajax call. The call is successful, hits the controller and returns. However, it will not stay on the same page. I tried referencing this only and did not work:

  • text box stays highlighted 2012-02-06

    After copying text into OneNote say from a web page, the text box initially is greyed out, moving the cursor outside of the text box removes the text box outline & greyed out colour as expected. My frustration with OneNote is when I subsequently

  • toggle UIButton text programmatically with a conditional statement 2012-04-23

    Here's my code (it's wrapped in an IBAction that is called when the button is pressed): if (myButton.currentTitle == @"test") { [myButton setTitle:@"test2" forState:UIControlStateNormal]; } if (myButton.currentTitle == @"test2") { [myButton setTitle:

  • Loaded Office 2010. Now cannot view or work on many old Word docs saved in Word 2003. If I try, Word will not stay open. 2012-07-14

    Having loaded Office 2010 Home & Business successfully now cannot view or work on old docs saved in Word 2003 format. Word 2010 will not stay open. --------------Solutions------------- What do you mean Word will not stay open? Do you mean, every

  • Zoom level does not stay at 150% and keeps reverting back to 100%. 2012-12-27

    Original Title: zoom I have tried to "lock in" zoom at 150 but it will not stay keeps going back to 100, I can't read it that small. I have downloaded IE9 3 days ago could that be the trouble? I also have Window 7 64bit. I've went to customize, still

  • Colored text not showing 2013-07-17

    I'm having an issue with color formatted text not showing up in any of the Office 2010 programs. I've checked that the Windows High-contrast setting is not on. When I send an email in Outlook, other forms of formatting (bold, underline and highlight)

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.116 (s). 11 q(s)