views:

280

answers:

1

Hello Everyone,

I have what seams simple, but I just cannot get it to work. I have a variable coming into a ViewController(presented by a modal view) and in the viewController I access the appDelelgate to get at a variable in the passed NSArray. I can verify that the variable is availible with my NSLog just before I make a mess of assigning it, so I know it is there. in the .h file is the following;

@class ViolinMakerAppDelegate;


@interface DetailsViewController : UIViewController
{

    ViolinMakerAppDelegate *dappDelegate;
 DetailsViewController *detailsView;


 IBOutlet UIViewController *modalViewController; 
 IBOutlet UITextView *violinMakerDescription;

}

@property (retain, nonatomic) ViolinMakerAppDelegate *dappDelegate;

@property (nonatomic, retain) DetailsViewController *detailsView; 
@property(nonatomic, assign) UIViewController *modalViewController;

@property (nonatomic, retain) IBOutlet UITextView *violinMakerDescription;

In the .m file is the following.

    #import "DetailsViewController.h"
    #import "ViolinMakerAppDelegate.h"

    @implementation DetailsViewController
    @synthesize detailsView, violinMakerDescription, dappDelegate;
        - (void)viewWillAppear:(BOOL)animated
        { 

         dappDelegate = (ViolinMakerAppDelegate *) [[UIApplication sharedApplication] delegate];
         DetailsViewController *detailsViewController = [[DetailsViewController alloc]initWithNibName:@"DetailsViewController" bundle:nil];
         self.detailsView = detailsViewController;
    // Tried below, but the variable is not getting to the IBOutlet..     
    NSString *aviolinMakerDescription = [dappDelegate.violinMakers description];
    [self.detailsView.violinMakerDescription setText:aviolinMakerDescription];

NSLog(@"violinMakerDescription: %@", [dappDelegate.violinMakers description]);

         // tried -----> [self.detailsView.violinMakerDescription setText:[dappDelegate.violinMakers description]];

        }

I am sure this is pretty simple as I know the variable 'description' has what I want in it. I just keep getting nothing but the static text in the IB. I am sure I have the IB connected right, as I have it working similarly from a the RootViewController pushing another view, and all connections are the same and very simple. One IB outlet, one UITextView.

It sounds crazy to me, but is there any reason that because this view is in a modal view, that it cannot load variables into text fields, only send variables back into the program from a modal controller?

Anyone out there like to help me get this through my dense skull what I am missing for this final code to assign it to the IBOutlet?? Thanks in Advance, Kirk

@Scott I have tried everything, and thought that was what was needed... not sure really. Here is where I present modally the DetailsViewController, from another view, which is pushed by the root controller.

case 0: 
     {
      DetailsViewController *detailsViewController = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
      UINavigationController *aDetailsViewController = [[UINavigationController alloc] initWithRootViewController:detailsViewController];
      self.detailsView = detailsViewController;   

      // °°°[self.view addSubview:detailsViewController.view];
      // self.violinMakerView = violinMakerViewController;
      // [[self navigationController] pushViewController:detailsViewController animated:YES];



      dappDelegate = (ViolinMakerAppDelegate *) [[UIApplication sharedApplication] delegate];
      // This does show the variable is loaded here too.
      NSLog(@"violinMakerDescription from Details Segment: %@", [dappDelegate.violinMakers description]);
      // attempting to load it here as well rem out doesn't change things
      [violinMakerDescription setText:[dappDelegate.violinMakers description]];

      // NSLog(@"violinMakerDescription loaded in segment Segment: %@", violinMakerDescription);


      [self presentModalViewController:aDetailsViewController animated:YES];


      [violinMakerView release];
      [detailsViewController release];
      [aDetailsViewController release];

      break;

I really don' know what I need in the DetailsViewController in the text above to get it to load the variable.... I hope it makes sense to you. Thank you for anything you can help on or shed some light on!

+1  A: 

In your implementation, is DetailsViewController the modal controller for the view? If so, I don't understand the need for the following code:

DetailsViewController *detailsViewController = [[DetailsViewController alloc]initWithNibName:@"DetailsViewController" bundle:nil];
self.detailsView = detailsViewController;

It seems you are loading another view and assigning the description in it and never showing it in the same view. I am not sure how you have your code for the model view loading so item seems you could try the following in viewWillAppear:(BOOL):

[violinMakerDescription setText:[dappDelegate.violinMakers description]];

That would set your current view's description and should be all you need unless I am missing something.

Scott Densmore