[英]Pass data between View Controllers - Storyboards segues
我不確定為什么,但是在我的項目中不起作用。 我做的和一百萬個教程完全一樣。
我有帶TableView的TableViewController和有關細節的簡單ViewController。
在h文件中我詳細聲明了ViewController:
@property (strong, nonatomic) NSString *testText;
然后,在@implementation下的m文件中:
@synthesize testText;
在帶有列表的TableViewController中,我有:
//declared above: UIViewController *ticketDetailViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *destinationTitle = [[ticketArray objectAtIndex:[indexPath row]] pkey];
[ticketDetailViewController setTitle:destinationTitle];
一切都很好。 標題正確,因此必須存在連接。 但是,現在我想傳遞其他數據…所以我做了testText屬性,我想從TableViewController訪問,但是我不能:/
錯誤說:在'UIViewController *'類型的對象上找不到屬性'testText'
真正奇怪的是..在調試期間,有testText(如下面的屏幕所示):
雖然當我想實現它..時找不到:
有人知道發生了什么嗎?
更改:
UIViewController *ticketDetailViewController = [segue destinationViewController];
至:
TicketDetailViewController *ticketDetailViewController = (TicketDetailViewController *)[segue destinationViewController];
以便編譯器知道您使用的是哪種類型的類(並且它可以找到/完成適當的屬性)。
您需要將局部視圖控制器聲明為局部視圖控制器,而不是UIViewController。
ViewController *ticketDetailViewController = [segue destinationViewController];
代替
UIViewController *ticketDetailViewController = [segue destinationViewController];
同樣,您應該使用copy而不是strong聲明您的testText屬性。
@property (copy, nonatomic) NSString *testText;
//declared above: UIViewController *ticketDetailViewController = [segue destinationViewController];
您不希望使用UIViewController類的ViewController,而需要TicketDetailViewController,或者已將目標ViewController類命名為。 在該類中,我假設您有一個名為testText的屬性。
正確的聲明應該是
TicketDetailViewController *ticketDetailViewController = [segue destinationViewController];
其次,您不再需要此功能。 編譯器會自動執行此操作。
@synthesize testText;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.