簡體   English   中英

當我在導航控制器中按ViewController時,顯示黑屏-空視圖

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM