-1

iOS アプリ プロジェクトに問題があります。SearchViewController の値を ResultGeneralInfoViewController に転送したいと考えています。バグや問題はありませんが、動作しません。

ここで私の 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;

および 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;
}

何か案は?

4

2 に答える 2

4

ResultGeneralInfosViewController を初期化しておらず、割り当てただけです。init最初に初期化するために、適切なメソッドを呼び出します。例えば:

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

オブジェクトが初期化されたら、必ずプロパティを設定してください。

于 2013-04-06T16:17:34.283 に答える
1

ではdidSelectRowAtIndexPath、 のインスタンスを作成しますがResultGeneralInfosViewController、それに対して何もしません。ナビゲーションコントローラーを使用する場合は、追加する必要があります

[self.navigationController pushViewController:detailViewController animated:YES];
于 2013-04-06T16:17:03.737 に答える