UILabel Question

Discussion in 'iOS Programming' started by LunchBox8484, Apr 23, 2010.

  1. LunchBox8484 macrumors member

    Joined:
    Mar 5, 2006
    #1
    So, I have a Label I dropped into my View using interface builder with the default text "Label", called testString. I am loading the text: "test1,test2,test3" from an outside view, and on the label it shows up as such, so it's working.

    However, when I try to output "testString.text" elsewhere, the output is "Label".

    Any ideas????
     
  2. kaydell.leavitt macrumors regular

    Joined:
    Apr 19, 2010
    #2
    Are you using the setText: method to set the label?
     
  3. csnplt macrumors 6502

    csnplt

    Joined:
    Aug 29, 2008
    Location:
    Chicago Area
    #3
    What code are you using? Try this:

    Code:
    NSString *labelText = testString.text;
    NSLog(@"Here is what is displayed in testString Label: %@", labelText);
    
     
  4. LunchBox8484 thread starter macrumors member

    Joined:
    Mar 5, 2006
    #4
    Nope, i'm using:

    testViewController.testString.text = @"test1,test2,test3";
     
  5. LunchBox8484 thread starter macrumors member

    Joined:
    Mar 5, 2006
    #5
    Here is what is displayed in testString Label: Label

    Yet the label on the page shows "test1,test2,test3"
     
  6. LunchBox8484 thread starter macrumors member

    Joined:
    Mar 5, 2006
    #6
    [​IMG]

    Called from:
    [testViewController.testString setText:mad:"test1,test2,test3"];

    Outputted here:
    NSMutableArray *array = [[NSArray alloc] initWithArray:[testString.text componentsSeparatedByString:mad:","]];
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  8. LunchBox8484 thread starter macrumors member

    Joined:
    Mar 5, 2006
    #8
    Yeah... can't do that? (I'm a newb)

    Well... I dragged the label onto the table and it displays the correct text in that label. But then when I try to get the text of that label in that View and output it into a table cell, it just gives me "Label".

    If not, how do you pass a string of text to a UITableView?
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    If you want your UILabel to be part of a UITableViewCell (a subview), then you'll need to set and retrieve its value using table view programming.
     
  10. LunchBox8484 thread starter macrumors member

    Joined:
    Mar 5, 2006
    #10
    I don't really. All I want is to access a variable passed from a UITableViewController to another UITableViewController. I am using a label because I don't know how to otherwise. Is there a better way?

    I also tried this:

    in 1stUITableViewController.m:
    in 2ndUITableViewController.h:


    in 2ndUITableViewController.m:

    And in the console I get: my ns string = (null)
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    Try setting theString before you push the view controller.
     
  12. LunchBox8484 thread starter macrumors member

    Joined:
    Mar 5, 2006
    #12
    Ok, that works, sort of...

    It works the first time I click a row to send the cell value (on 1stUITableViewController.m), but every other time I click it, it's sends the same cell value (depending on what I clicked the first one), not the correct cell value of what I clicked. However, the title of the tableview on 2ndUITableViewController.m is changing correctly. Is there anything else I can do?

    1stUITableViewController.m:
    Also, it looks like it's only outputting the message on the console once, not every time you enter the 2ndUITableViewController. Do I need to refresh that somehow?
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    Think about when, and how often, viewDidLoad gets called.
     

Share This Page