[UILabel setText:UIProgressView]

Discussion in 'iOS Programming' started by aukemid, Mar 26, 2010.

  1. aukemid macrumors newbie

    Joined:
    Mar 26, 2010
    #1
    I have a UIProgressView and a UILabel.

    Now I'm trying to set the progress in the label as a precentage.

    Code:
    [progressLabel setText:myProgress.progress];
    This doesn't work, can someone tell me how to do this?

    Edit:

    I also have a UITextField of which I can set the text using:
    Code:
    - (IBOutlet)copy:(id)sender
    {
    	[textLabel setText:[textField text]];
    }
    I got this from a tutorial but I get the error:
    "control reaches end of non-void function"

    When I changed it to a void function I got the same error without the "non"?
    How could I do this?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Code:
    myProgress.progress
    returns a float. This is a primitive type (i.e non-object) representing a floating point number
    Code:
    progressLabel setText:
    requires that the parameter passed is a NSString *, a pointer to an object.

    Surely it's amazingly clear why this won't work and what you need to do to fix it? In case it isn't you need to turn what you have (a float) into what you want (a NSString *). Bonus points if the contents of the string represent the same as the float.

    The simplest way will be to use NSNumber's numberWithFloat: and stringValue methods.
     
  3. aukemid thread starter macrumors newbie

    Joined:
    Mar 26, 2010
    #3
    Actually thanks for nothing (, but trying to help).

    I know about the casting/converting stuff, but I couldn't find a good example.

    Now I have this:
    Code:
    NSString *string = [NSString stringWithFormat:@"%.0f", myProgress.progress * 100];
    [progressLabel setText:string];
    This works, but how do I add something to a string in objc? Like += "%"
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Before asking questions you should read the documentation.

    The NSString documentation clearly says "The NSString class declares the programmatic interface for an object that manages immutable strings." So you cannot alter a NSString value.

    It then goes on to to document three methods under a heading "Combining Stings". I leave it to you to read the documentation on those methods.

    If you are totally unwilling to do the absolute minimum of reading yourself to work out the answers why do you expect us to be less lazy? :rolleyes:
     
  5. aukemid thread starter macrumors newbie

    Joined:
    Mar 26, 2010
    #5
    I don't expect you to read the documentation for me, but I expect that if you answer a question you know the answer. And if I have to read a book for every little question I have, forums would become quite useless.

    If you just want to discuss difficult situations one a forum, you should just ignore the little questions.

    I have a lot experience with Java, a bit of C and started learning Objective C yesterday. If you ask me a question as simple as this about Java, I would just give the answer or a link to a clear answer. Most people don't learn programming by reading a book (api), but by try and error.
     
  6. potaco macrumors regular

    Joined:
    Mar 12, 2010
    #6
    So, I was able to follow his link, find the "Combining Strings" header, and find the correct method to do exactly what you asked... all in about 30 seconds. And it showed the usefulness of the Apple documentation. Instead of bickering about not being told the specific code to do what you want, you should spend a few seconds following his advice to realize that it's more helpful this way (give a man a fish, etc).
     
  7. aukemid thread starter macrumors newbie

    Joined:
    Mar 26, 2010
    #7
    My previous post was just a reaction on his last line.

    I did what robbieduncan suggested and I found the solution.

    And I didn't meant to sound so :mad:, but while searching other forums I got a bit :(, because almost every answer tells to read the api without any help.
    So I got a bit pissed, sorry.
     
  8. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #8
    Fixed that for you.

    If the forums weren't clogged with people asking basic questions that could be solved by a quick read of the (very good) documentation, there might be some more interesting discussion going on.
     
  9. aukemid thread starter macrumors newbie

    Joined:
    Mar 26, 2010
    #9
    Imagine you know what a String is and how it works, but you have no idea how it is in this language, it would take quite some time finding the link robbie gave me. Using this forum I got in about a minute (without the time of this discussion).

    This way I learn the language perhaps twice as fast, and in some time I'll understand the language enough to participate in your big discussions.

    So divide the threads in newbie questions and discussions. People who don't want to help with the simple problems don't read the newbie threads. Problem solved.
     
  10. potaco macrumors regular

    Joined:
    Mar 12, 2010
    #10
    Trial and error only works to a certain extent. You need to have some fundamental knowledge of the language before knowing where to start trying in the first place. You don't know what you don't know... if you don't know what a method is named, you'll likely have to search some sort of documentation anyway.

    If I'm trying to concatenate strings in Language X and I don't know anything about it, I wouldn't waste time trying:

    string3 = string1 + string2;
    string3 = string1 . string2;
    string3 = string1.concatenate(string2);
    string3 = concatenateStrings(string1,string2);
    etc

    I'd just google it or something. I agree with Luke Redpath, simple questions that can easily be answered with a quick search do nothing but clutter forums. At some point, you have to take the initiative. Another benefit of actually searching is that you have a good chance of finding related methods, etc that might actually fit your needs better than what you first thought.
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    Oh, I'm pretty sure robbieduncan does know the answer. ;)

    Not necessarily. Here's a quick way to get to the class reference in the Developer Documentation, right from within Xcode. Option-double-click the class name (works for other elements as well), and you will get a popup with a brief overview of the class. Click the book icon in the header and you will be taken to the class reference via Developer Documentation. This is just one of the various tricks you can use within Xcode to make your coding better and easier.

    Maybe newbie questions should add "Newbie Question: ..." to their thread title then. ;)
     
  12. aukemid thread starter macrumors newbie

    Joined:
    Mar 26, 2010
    #12
    Thanks for that last tip.

    I don't agree with the simple question issue, but lets drop. For the cluttering.
     

Share This Page