Code Monkey home page Code Monkey logo

Comments (4)

cbpowell avatar cbpowell commented on August 17, 2024

I'm not seeing the issue as you describe it, although I don't see any downside (at a first glance) to making the change. Could you post a bit more of your code? Like how you're setting up the label and where exactly you set it to @"" the first time? Also setting the labelText to [NSString string] is actually the same as setting it to @"" (because [[NSString string] isEqualToString:@""] == YES)

from marqueelabel.

calinbodnar avatar calinbodnar commented on August 17, 2024

Ok..let me give you an example:

I have the following code in viewDidLoad:

_label = [[MarqueeLabel alloc] initWithFrame:CGRectMake(30, 100, 100, 30) duration:5.0 andFadeLength:25.0];
[_label setText:@""];// initially no text should be displayed
[_label setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:_label];

where _label is an instance variable.

Then I have an UIButton and the corresponding IBAction (on UIControlEventTouchUpInside event):

  • (IBAction) dummyButtonPressed:(id)sender
    {

       [_label setText:[[_label text] stringByAppendingString:@"M"]];
    

    }

If self.labelText is set to nil (as currently is: self.labelText = nil in - (void)setupLabel method from MarqueeLabel), then the line of code [_label setText:[[_label text] stringByAppendingString:@"M"]]; has no effect --> no text is displayed no matter how many times I press the button...BUT if you change the self.labelText = nil; to self.labelText = [NSString string]; (in - (void)setupLabel method from MarqueeLabel.m) everything works as expected.

Hope now everything is more clear..

Regards,
Calin B.

from marqueelabel.

cbpowell avatar cbpowell commented on August 17, 2024

Ah, gotcha, I see what you mean - the problem is showing up because of using the stringByAppendingString: method on [_label text]. The property text just returns self.labelText, which at that point is nil so stringByAppendingString: does nothing.

Good catch, thanks! The latest commit should fix your problem, although I'm using self.labelText = @"" just so it's explicitly obvious it's being set to an empty string in setupLabel.

from marqueelabel.

calinbodnar avatar calinbodnar commented on August 17, 2024

Glad to help.

from marqueelabel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.