Label.text or TextView.text access NSSting

Discussion in 'iOS Programming' started by andyiapan, Mar 2, 2010.

  1. andyiapan macrumors newbie

    Joined:
    Feb 28, 2010
    #1
    if i have NSString *a;
    a[0] = @"hello,";
    a[1] = @"i am peter,";
    a[2] = @"how are you?";

    how can i display all text in Label.text?

    Label.text = a[0] + a[1] + a[2];

    Output:
    hello,i am peter,how are you?
    in Label

    THXXXX
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I think you are confused. NSString *a should be pointing at a single NSString object. Not at an array of NSStrings.
     
  3. andyiapan thread starter macrumors newbie

    Joined:
    Feb 28, 2010
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    If you really want to. I would suggest you look at the NSString documentation for appending them: + won't work.
     
  5. andyiapan thread starter macrumors newbie

    Joined:
    Feb 28, 2010
    #5
    Thx yr suggestion, i want to use a for loop, but still can't find the solution:(

    for(int i = 0; i < 3; i++)
    XX = XX + a;
    label1.text = XX
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    You cannot combine NSString objects with the + operator. This is not Java with dodgy special-case overrides for one type of object. Open the NSString documentation and search for append methods...
     
  7. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #7
    You will want to look at the string appendwithformat methods that is contained in the NSString class.
     
  8. andyiapan thread starter macrumors newbie

    Joined:
    Feb 28, 2010
    #8
    THanks bro, i use appendwithformat methods and it's worked:eek:
     

Share This Page