[英]when i push viewcontroller in navigation controller, shows black screen - empty view
我嘗試使用情節提要InstantiateViewControllerWithIdentifier,它工作正常,但我需要委托方法,因此在從FirstViewController打開SecondViewController時添加了以下代碼,
SecondViewController *svc=[[SeconViewController alloc] init];
svc.delegate=self;
[self.navigationController pushViewController:svc animated:YES];
但是它會打開黑屏。真的很感謝您提供任何幫助。 謝謝。
secondViewController.h文件
@protocol sendDataToAudioDelegate <NSObject>
-(void)sendData:(NSMutableArray *) data;
@end
@interface AudioSavedFilesViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *fileTable;
@property (strong, nonatomic) NSMutableArray *selectedIndices;
@property (strong, nonatomic) AVAudioPlayer *audioplayer;
- (IBAction)selectedFiles:(id)sender;
@property (nonatomic,assign)id <sendDataToAudioDelegate> delegate;
@end
這里:
SecondViewController *svc= [self.storyboard instantiateViewControllerWithIdentifier @"identifier"];
svc.delegate=self;
您正在嘗試設置SecondViewController的委托屬性。 但是這樣做時出現的錯誤是:
在對象類型“ UIViewController”上找不到屬性委托
建議您的SecondViewController類沒有名為委托的屬性。 因此,您需要:
@interface SecondViewController
@property (nonatomic, assign) id delegate;
@end
原因是因為您正在創建SecondViewController
全新實例並將其推送到navigationController
。 您根本不使用storyboard
場景,因此,添加和連接的所有UI
元素也將不起作用。 您需要還原為使用instantiateViewControllerWithIdentifier
您仍然可以在執行操作的同時使用delegate
,如下所示:
SecondViewController *svc= [self.storyboard instantiateViewControllerWithIdentifier @"identifier"];
svc.delegate=self;
[self.navigationController pushViewController:svc animated:YES];
編輯閱讀完您的評論后,我認為您尚未將情節SecondViewController
的場景設置為使用SecondViewController
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.