目前,我正在开发一个 iPad 应用程序,该应用程序在第一个场景上显示幻灯片 - 使用分页 UIScrollView 实现。当我单击幻灯片中的一页时,我想推送一个新的 VC(到一个新场景,它应该显示多个缩略图……如果您愿意,可以是一种细节层)。
我怎样才能通过segue做到这一点?目前,我只是拉出一个新的 VC,并将 SlideshowVC 与场景中的下一个 VC 连接 - 但没有任何反应。我研究了几个教程,但大多数都使用一个连接到下一个 VC 的按钮。它是否能够简单地将 SlideshowVC 与下一个 VC 连接,或者我真的需要在整个滚动视图上绑一个按钮并将按钮与下一个 VC 连接吗?
目前我的场景如下图所示。第一个是 NavVC,第二个是 SlidehsowVC,第三个是 DetailVC。

我使用新闻源制作应用程序,该应用程序必须在其他 ViewController 上打开。但无法通过segue传递数据。
带新闻源的视图控制器
class SecondViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var titlenews = ""
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "newsfeedCell", for: indexPath) as! NewsFeedCell
cell.newsfeed_title.text = self.news?[indexPath.item].headline
cell.newsfeed_topic.text = self.news?[indexPath.item].topic
cell.newsfeed_time.text = timetime(from: (self.news?[indexPath.item].time)!)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("tableview")
let vc = storyboard?.instantiateViewController(withIdentifier: "newsBody") as? NewsBody
vc?.labeltext = (self.news?[indexPath.item].headline)!
print((self.news?[indexPath.item].headline)!)
self.navigationController?.pushViewController(vc!, animated: true)
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
} …Run Code Online (Sandbox Code Playgroud) 我尝试使用故事板与表视图segue到控制器视图,应该显示我的图片.问题是,当我按下任何"单元格"时,应用程序会崩溃.
这是问题代码:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"ShowPhoto"])
{
DetailsViewController *dvc = [segue
destinationViewController];
NSIndexPath *path = [[self tableView] indexPathsForSelectedRows];
Photo *pic = [photosArray objectAtIndex:[path row]];
[dvc setCureentPic: pic];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是NSIndexPath的行...我认为原因是我尝试将数组插入NSIndex.xcode警告:使用类型为"NSArray"的表达式初始化"NSIndexPath*__ strong"的指针类型不兼容.
crush消息:无法识别的选择器发送到实例[__NSArrayI行].我该如何解决这个问题?
我有segue设置为:
和tableView行选择:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
// Ensure controller knows which dataset to pull from,
// so detail view is correct
var friendChat: Friend!
if searchController.active && searchController.searchBar.text != "" {
friendChat = filterMappedFriends[indexPath.row]
} else {
friendChat = mappedFriends[indexPath.row]
}
// Now set the conditional cases: if a friend then chat, if user then friend request if not user then can invite them:
if(friendChat.statusSort == 2) {
self.performSegueWithIdentifier("showIndividualChat", sender: friendChat)
} else …Run Code Online (Sandbox Code Playgroud) 我正在尝试将包含在收集视图单元格中的标签发送到带有segue的另一个视图控制器。
我的计划是,当用户点击集合视图单元格时,该应用程序会转到下一个视图控制器,在该视图控制器中,导航栏的标题将在所选集合视图单元格中显示标签的文本。
我已经试过了:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CCCollectionViewCell
//itemSelected = items[indexPath.row] as String
itemSelected = cell.pLabel.text!
print(itemSelected)
}
Run Code Online (Sandbox Code Playgroud)
在prepareForSegue中,由于不确定如何工作,因此我没有编写任何代码。
我注释掉了块“ ..items [indexPath.row] as String”,因为它不会显示标签,并添加了打印功能以查看将输出的内容,但仅输出情节提要中给出的名称。
我是Xcode的新手,所以对didSelect和prepareForSegue不熟悉。我要做的就是将带有收集的视图单元格中的文本发送到另一个视图控制器。

如您所见,屏幕流程如下:
点击"屏幕A"的"按钮2"后,应用程序会在同一个具有标签栏的故事板中显示"屏幕B".点击"屏幕B"的"红色标签"后,应用程序会显示"绿色按钮"(右上角).点击"屏幕B"的"绿色按钮"后,应用程序会显示"故事板2"的"屏幕C".
点击"屏幕C"的后退按钮后,我需要回到"故事板1"的"屏幕B",无论"屏幕C"出现在哪里,"故事板2"的"屏幕C"应该消失从上到下.
是否有可能这样做,如果是,那么如何?