I know this has been asked many times, but I cant find answer to my problem.
I want to extract a string variable from another file.
I wrote such:
NSMutableString *universalString; in AppDelegate.m
I import this string in MainViewController.m:
extern NSMutableString *universalString;
In
`- (void)tableView:(UITableView *)tableView1 didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView1 deselectRowAtIndexPath:indexPath animated:NO];
TestViewController *viewCon = [[TestViewController alloc]initWithNibName:@"viewCon" bundle:nil];
[self.navigationController pushViewController:viewCon animated:YES];
[viewCon release];
`universalString = [self.array objectAtIndex:indexPath.row];
}`
In TestViewController.m, also extern NSMutableString *universalString;
- (void)viewDidLoad {
UITextView *newtextview = [[UITextView alloc] initWithFrame: CGRectMake(10, 10, 200, 200)];
newtextview.backgroundColor = [UIColor blackColor];
[newtextview setTextColor:[UIColor whiteColor]];
newtextview.text = universalString;
[self.view addSubview:newtextview];
[newtextview release];
}
I want to extract this universalString from MainViewController., but nothing happens until I click twice forth and back through, then this universalString appear in TestViewController.m.
What did I do wrong?
Ok I found a little bit of code in my email, you should hopefully be able to apply it:
What you have to do is create an app delegate with universalString set up as a property. Include it in both view controllers, and use the following to set/get it.
Again, I’m a bit rusty(and can’t check my own source code because I don’t have access anymore), I hope this is enough for you to be able to apply it.