Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-25-2010, 05:51 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 20
Sniark is on a distinguished road
Default Keeping a variable from one nib to the other...

Hey eveyone,

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];
}
Many thanks to everyone,
Sniark is offline   Reply With Quote
Old 03-25-2010, 06:36 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
jmascore is on a distinguished road
Default

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.

Cheers,
Joe
jmascore is offline   Reply With Quote
Old 03-25-2010, 06:48 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 20
Sniark is on a distinguished road
Default Would you have an example?

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?

Many thnaks
Sniark is offline   Reply With Quote
Old 03-25-2010, 07:19 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

Code:
// 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;
nobre84 is offline   Reply With Quote
Old 03-25-2010, 07:27 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 20
Sniark is on a distinguished road
Default

Quote:
Originally Posted by nobre84 View Post
Code:
// 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;
Thank you very very much
Sniark is offline   Reply With Quote
Old 03-25-2010, 07:38 AM   #6 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 20
Sniark is on a distinguished road
Default

Quote:
Originally Posted by nobre84 View Post
Code:
// 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



Any idea???
Sniark is offline   Reply With Quote
Old 03-25-2010, 07:50 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

You probably declared the property description in the .h file, but forgot to add the keyword @synthesize description in your .m file.
nobre84 is offline   Reply With Quote
Old 03-25-2010, 08:04 AM   #8 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 20
Sniark is on a distinguished road
Default

Quote:
Originally Posted by nobre84 View Post
You probably declared the property description in the .h file, but forgot to add the keyword @synthesize description in your .m file.
Here my .h
Code:
@interface PlatsViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,BlogRssParserDelegate> {

	ArticleViewController *showArticleViewController;

	
	IBOutlet UIButton *retourPlats;
	
	BlogRssParser * _rssParser;
	UITableView * _tableView;
	MProjectAppDelegate * _appDelegate;
	UIToolbar * _toolbar;
	
	IBOutlet UITextView *description;
	
	NSString* ArticleDescription;

}
-(IBAction)retourPlatsClick:(id)sender;

@property (nonatomic, retain) UITextView *description;

@property(nonatomic, retain) ArticleViewController *showArticleViewController;

@property (nonatomic,retain) IBOutlet NSString* ArticleDescription;

@property (nonatomic,retain) IBOutlet BlogRssParser * rssParser;
@property (nonatomic,retain) IBOutlet UITableView * tableView;
@property (nonatomic,retain) IBOutlet UIToolbar * toolbar;
@property (nonatomic,retain) IBOutlet MProjectAppDelegate * appDelegate;

-(void)toggleToolBarButtons:(BOOL)newState;

Is the description property good?

And here is the head of my .m
Code:
@implementation PlatsViewController


@synthesize rssParser = _rssParser;
@synthesize tableView = _tableView;
@synthesize appDelegate = _appDelegate;
@synthesize toolbar = _toolbar;

@synthesize	description;
@synthesize ArticleDescription;

@synthesize	showArticleViewController;
I don't get what's wrong....
Sniark is offline   Reply With Quote
Old 03-25-2010, 08:12 AM   #9 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 20
Sniark is on a distinguished road
Default

Quote:
Originally Posted by nobre84 View Post
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
Sniark is offline   Reply With Quote
Old 03-25-2010, 08:36 AM   #10 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 26
ugur is on a distinguished road
Default

You're trying to assign NSString to an UITextView object.

self.showArticleViewController.description = ArticleDescription;

should be:

[self.showArticleViewController.description setText: ArticleDescription];
ugur is offline   Reply With Quote
Old 03-25-2010, 08:52 AM   #11 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 20
Sniark is on a distinguished road
Default

Quote:
Originally Posted by ugur View Post
You're trying to assign NSString to an UITextView object.

self.showArticleViewController.description = ArticleDescription;

should be:

[self.showArticleViewController.description setText: ArticleDescription];
No the variable is still NULL....
Sniark is offline   Reply With Quote
Old 03-25-2010, 09:20 AM   #12 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

Make sure your description outlet is correctly connected in IB to the UITextView, then assign as ugur posted.
nobre84 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone sdk, nib, variable

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 344
12 members and 332 guests
akacaj, c2matrix, cgokey, esoteric, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Sonuye857, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,652
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Sonuye857
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:17 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0