我有一個UILabel在我已經連接到屬性的界面生成器,但它通過視圖控制器上的viewDidLoad保持零。我一直在介紹,只要DetailViewController初始化,標籤屬性就在那裏,但它是零,它似乎從未被初始化。UILabel永遠不會初始化viewDidLoad
它一直在工作,直到我從導航控制器上使用segues切換到執行pushViewController。
// DetailsViewController.h
#import <UIKit/UIKit.h>
#import "TLitem.h"
@interface DetailsViewController : UIViewController
@property (nonatomic, strong) TLitem *entry;
@property (weak, nonatomic) IBOutlet UILabel *entryLabel;
@end
然後在另一視圖控制器表格視圖:
// EntryListViewController.m
DetailsViewController *details = [[DetailsViewController alloc] init];
[details setEntry:entry];
[self.navigationController pushViewController:details animated:YES];
而在viewDidLoad中:
// DetailsViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor yellowColor]];
TLitem *entry = [self entry];
UILabel *label = [self entryLabel];
label.text = [entry valueForKey:@"text"];
你提到你塞格斯改爲編程推你的視圖控制器。向我們展示您實例化它的代碼。 –
如果您的視圖控制器視圖和問題標籤是在故事板中定義的,則應該將其實例化爲'UIStoryboard'實例。 –
實例化視圖控制器?這是上面NewEntryListViewController.m的第一行。 – thisAnneM