-1

I have a problem with my iOS App Project. I want to transfer a value of my SearchViewController to my ResultGeneralInfoViewController. There are no bugs or issues but it doesn't work.

Here my Code in my SearchViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *item = [searchResults objectAtIndex:[indexPath row]];


    ResultGeneralInfosViewController *detailViewController = [ResultGeneralInfosViewController alloc];
    detailViewController.companyName = [item objectForKey:@"companyName"];
    NSLog([item objectForKey:@"companyName"]);
}

ResultGeneralInfoViewController.h

@interface ResultGeneralInfosViewController : UIViewController {

    NSString *companyName;
}

@property NSString *companyName;

@property (weak, nonatomic) IBOutlet UILabel *companyNameLabel;

and ResultGeneralInfoViewController.m

@implementation ResultGeneralInfosViewController

@synthesize companyName;

//Outlets
@synthesize companyNameLabel;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    companyNameLabel.text = self.companyName;
}

Any ideas?

DerFuchs10
  • 135
  • 1
  • 2
  • 12

2 Answers2

4

You have not initialized your ResultGeneralInfosViewController, only allocated it. Call the appropriate init method in order to initialize it first. For example:

ResultGeneralInfosViewController *detailViewController =
    [[ResultGeneralInfosViewController alloc] initWithNibName:@"NibName" bundle:nil];

Make sure you set the property once the object has been initialized.

1

In didSelectRowAtIndexPath, you create an instance of ResultGeneralInfosViewController, but you do nothing with it. If you use a navigation controller, then you should add

[self.navigationController pushViewController:detailViewController animated:YES];
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382