我的iOS App Project出了问题。我想将我的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;
}
有什么想法吗?
答案 0 :(得分:4)
您尚未初始化ResultGeneralInfosViewController,仅分配了它。调用相应的init
方法以便首先对其进行初始化。例如:
ResultGeneralInfosViewController *detailViewController =
[[ResultGeneralInfosViewController alloc] initWithNibName:@"NibName" bundle:nil];
确保在初始化对象后设置属性。
答案 1 :(得分:1)
在didSelectRowAtIndexPath
中,您创建了ResultGeneralInfosViewController
的实例,但您没有对其执行任何操作。如果您使用导航控制器,则应添加
[self.navigationController pushViewController:detailViewController animated:YES];