Reputation: 99
I have a error in my script, it doesn't works. but I don't know how to change it. I'm using 2 views, I'd like to use if/else for changing the text on the favoriteColorLabel on the second view from the first. If someone know the problem, please help me. Th My code :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==1) {
DetailVC.favoriteColorLabel=@"Bonjour";
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
dvController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:dvController animated:YES];
}
}
Thanks.
Upvotes: 0
Views: 183
Reputation: 1079
I would consider setting a label in the second view from a method in the first bad design and error prone.
What I would do, is give your detail view controller a property
that is an NSString *
. After you create the detail view controller from your first controller, you pass the text @"Bonjour"
to that property (by using its setter method) and then you can present the detail view controller. This second view controller can look at the value of its string and set the label accordingly.
The detail view controller is there to manage its own views, it should not need you first view controller to manage what's onscreen.
Upvotes: 0
Reputation: 11595
I think the error is on this line:
DetailVC.favoriteColorLabel=@"Bonjour";
It is most likely you actually want to set the text
attribute of your label like this:
DetailVC.favoriteColorLabel.text=@"Bonjour";
This is because the text
attribute is the text displayed by the label onscreen. You were setting the actual UILabel object to an NSString literal, which is probably not what you wanted to do.
Upvotes: 2
Reputation: 1506
You are setting Text to a label Thats why you are getting error in your code.
You need to do it as like this:
labelname.text = @"String";
Then your issue will resolve.
Hope it works.
Upvotes: 0