I'm trying to record a variable to display it on the next nib. It's a sort bit of code, and I4m not getting why it's not working...
Can please someone have look?
Here is the code (in .m)
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[self appDelegate] setCurrentlySelectedBlogItem:[[[self rssParser]rssItems]objectAtIndex:indexPath.row]];
[self.appDelegate loadNewsDetails];
NSString* ArticleDescription = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
// Variable has been properly recorded as it is displaying in the console
NSLog(@"ArticleDescription: %@", ArticleDescription);
// Calling the new nib
ArticleViewController *Click = [[ArticleViewController alloc] initWithNibName:@"ArticleViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.50];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:[self view]
cache:YES];
[self.view addSubview:Click.view];
// Trying here to set the variable but it doesn't work.
[self.showArticleViewController.description isEqual: ArticleDescription];
// The console says here it is equal to null
NSLog(@"self.showArticleViewController.description: %@", self.showArticleViewController.description);
[Click setTitle:@"Les Plats..."];
[self.view addSubview:Click.view];
[UIView commitAnimations];
}
I am not convinced this is best practice, but what I do is override the initWithNibName method and add an object to it, like Nsstring*)someString so when I call that method in the didSelectRowAtIndexPath method, I can add the string to the list of passed variables. Then in the initWithNibName methon in the new view controller I set an ivar to the variable. Another way to do it is to initialize the view controller, then use the newViewController.ivar = someLocalVar; call.
Again, not sure if it's best practice, but it works for me.
Thanks
I'm quite new to iPhone & objecyive-C dev... I'm not quite sure I understand this all. Would you be kind enough to post a piece of code exemple?
// Trying here to set the variable but it doesn't work.
[self.showArticleViewController.description isEqual: ArticleDescription];
You are not assigning the variable. The method isEqual only checks both objects for equality. To assign the description property you need to either use the setDescription method or use dot notation.
Code:
//assign using setter method
[self.showArticleViewController setDescription: ArticleDescription];
//or like this
self.showArticleViewController.description = ArticleDescription;
// Trying here to set the variable but it doesn't work.
[self.showArticleViewController.description isEqual: ArticleDescription];
You are not assigning the variable. The method isEqual only checks both objects for equality. To assign the description property you need to either use the setDescription method or use dot notation.
Code:
//assign using setter method
[self.showArticleViewController setDescription: ArticleDescription];
//or like this
self.showArticleViewController.description = ArticleDescription;
// Trying here to set the variable but it doesn't work.
[self.showArticleViewController.description isEqual: ArticleDescription];
You are not assigning the variable. The method isEqual only checks both objects for equality. To assign the description property you need to either use the setDescription method or use dot notation.
Code:
//assign using setter method
[self.showArticleViewController setDescription: ArticleDescription];
//or like this
self.showArticleViewController.description = ArticleDescription;
When I change the line, I get an error:
/Users/yanncadoret/Desktop/MM/MProject/Classes/PlatsViewController.m:153:0 /Users/yanncadoret/Desktop/MM/MProject/Classes/PlatsViewController.m:153: error: object cannot be set - either readonly property or no setter found
You probably declared the property description in the .h file, but forgot to add the keyword @synthesize description in your .m file.
I now get a warning whcih says /Users/yanncadoret/Desktop/MM/MProject/Classes/PlatsViewController.m:150:0 /Users/yanncadoret/Desktop/MM/MProject/Classes/PlatsViewController.m:150: warning: incompatible Objective-C types 'struct NSString *', expected 'struct UITextView *' when passing argument 1 of 'setDescription:' from distinct Objective-C type