0

I'm using Xcode 4.3.2 & iOS 5.1 simulator, and in my project I am using two View Controllers: testingViewController, and detailView. I want to set values for an NSString in detailView once I didSelect tableViewCell in testingViewController.

For that i used following code:

testingViewController.h

testingViewController.h

testingViewController.m

testingViewController.m

detailView.h

detailView.h

detailView.m

detailView.m

I get null values for both wordName and wordMeaning in the console.

Anyone have a solution? Thanks in Advance!

Yuva
  • 125
  • 3
  • 11

5 Answers5

3

If you have a storyboard segue between testingViewController and detailView, in your testingViewController's prepareForSegue: method you should change line

detailView *dVw = [[detailView alloc] init]; 

to

detailView *dVw = (detailView *)segue.destinationViewController;

Also, I recommend you to change in your detailView.h file the

@property (nonatomic, assign) NSString *YOUR_STRING; 

to

@property (nonatomic, copy) NSString *YOUR_STRING;
rmxmaster
  • 156
  • 15
1

Use

[[segue destinationViewController] setWordMeaning:meaningString];
[[segue destinationViewController] setWordName:wordTapped];

The problem is that you are creating new object of the detailView

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
  • i need one more help, my deployment target iOS 3.0+ so i may not use this segue feature any other code to replace this one so that it'l work on iOS 3.0 + devices. Thanks in Advance! – Yuva Jul 25 '12 at 14:17
  • You can't target for lower version of `iOS` which uses a `Framework` or `API` which is available for higher version of `iOS` – Inder Kumar Rathore Jul 25 '12 at 14:24
1

I wrote this for sharing data between classes. I hope it is useful for you.

ChrisH
  • 904
  • 6
  • 13
ilhnctn
  • 2,210
  • 3
  • 23
  • 41
0

Set your NSStrings to retain properties, not to assign. Also, when you change their value, always use

self.property = ...;

in order for the retain to take place. Otherwise, it will be released and you will get null or bad access.

Jorge Aguirre
  • 2,787
  • 3
  • 20
  • 27
0

create custom init method

declare in .h file 

    -(id)initWithWordName:(NSString*)myWordName andWordMeaning:(NSString*)myWordMeaning;

    and in .m file

    -(id)initWithWordName:(NSString*)myWordName andWordMeaning:(NSString*)myWordMeaning
    {
       self = [super init];
       if(self)
       {
         self.wordName = myWordName;
         self.wordMeaning = myWordMeaning;
       }
       return self;
    }

and also NSString property should be copy instead of assign, do change in your detail.h file

Rahul Lalit
  • 416
  • 2
  • 10
  • Ya i have done as you mentioned but it's not working again the console displays null Value. – Yuva Jul 25 '12 at 14:13
  • Inder is correct, in this way it will create new object of detailView – Rahul Lalit Jul 25 '12 at 14:17
  • Thanks for your reply.i need one more help, my deployment target iOS 3.0+ so i may not use this segue feature any other code to replace this one so that it'l work on iOS 3.0 + devices. Thanks in Advance! – Yuva Jul 25 '12 at 14:21
  • 1
    check this [Link](http://www.iphonesdkarticles.com/2009/03/uitableview-drill-down-table-view.html) – Rahul Lalit Jul 25 '12 at 14:29
  • Thank you that link 'l help me lot. – Yuva Jul 25 '12 at 14:36