-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"]);
}

结果GeneralInfoViewController.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 回答