Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LunchBox8484

macrumors member
Original poster
Mar 5, 2006
30
0
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????
 
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????

What code are you using? Try this:

Code:
NSString *labelText = testString.text;
NSLog(@"Here is what is displayed in testString Label: %@", labelText);
 
What code are you using? Try this:

Code:
NSString *labelText = testString.text;
NSLog(@"Here is what is displayed in testString Label: %@", labelText);

Here is what is displayed in testString Label: Label

Yet the label on the page shows "test1,test2,test3"
 
4545820299_70e5a07b9f_o.png


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

Outputted here:
NSMutableArray *array = [[NSArray alloc] initWithArray:[testString.text componentsSeparatedByString:mad:","]];
 
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?
 
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.
 
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:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MainAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.mainNavController pushViewController:2ndUITableViewController animated:YES];
self.2ndUITableViewController.theString = @"test1,test2,test3";
}

in 2ndUITableViewController.h:

@interface 2ndUITableViewController : UITableViewController
<UITableViewDelegate, UITableViewDataSource>{
NSString *theString;
}
@property (nonatomic, retain) NSString *theString;


in 2ndUITableViewController.m:

- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"my ns string = %@", theString);
}

And in the console I get: my ns string = (null)
 
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:
self.2ndUITableViewController.title = cellValue;
self.2ndUITableViewController.theString = cellValue;

MainAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.mainNavController pushViewController:2ndUITableViewController animated:YES];

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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.