简体   繁体   English

数据将tableview单元格传递到Swift中的标签栏视图控制器

[英]Data pass tableview cell to tab bar view controller in Swift

I am new to swift 我是新手

The tableview contain multiple images working fine this the code : 的tableview包含多个图像工作良好的代码:

             override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

                    let cell = tableView.dequeueReusableCell(withIdentifier: "Media", for: indexPath)as! MediaCustomTableViewCell               
                    let row = indexPath.row                       
                    let media = Mediainfo[row] as MediaEvent                
                    cell.DisplayDate.text = media.date                
                    cell.DisplayName.text = media.eventName                       
                    cell.selectionStyle = .none                        
                    cell.DisplayImage.downloadImageFrom(link:media.bannerImages, contentMode: UIViewContentMode.scaleAspectFit)

                    return cell
                }


                override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
                    return CGFloat.leastNormalMagnitude
                }


                override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
                {                    
                    let media = Mediainfo[(indexPath.row)] as MediaEvent                        
                    let ImageStoryboard = UIStoryboard(name: "Main", bundle: nil)                      
                    let  ImageController = ImageStoryboard.instantiateViewController(withIdentifier: "IMAGESCOL")as!ImagesCollectionViewController

Here I'm passing an image to a collection view but its not working: 在这里,我将图像传递到集合视图,但是它不起作用:

                    ImageController.RecivedData1 = media.bannerImages                                            
                    let storyboard = UIStoryboard(name: "Main", bundle: nil)                      
                    let tabcontroller = storyboard.instantiateViewController(withIdentifier: "IMAGEVID") as! UITabBarController

                    navigationController?.pushViewController(tabcontroller, animated: true)

                }

After select any image in tableview cell image should show at tab bar with collection view. 选择表格视图中的任何图像后,单元格图像应显示在带有集合视图的选项卡栏上。 I am showing images and videos categories wise I can use tab bar controller 我正在明智地显示图像和视频类别,可以使用标签栏控制器

Data pass to: 数据传递到:

Tableview ---> tab bar controller ===> 2 collection views Tableview --->标签栏控制器===> 2个集合视图

How can pass the tableview images data to collection using tab bar controller? 如何使用标签栏控制器将tableview图像数据传递给集合?

In your code 在你的代码中

let ImageStoryboard = UIStoryboard(name: "Main", bundle: nil)
let ImageController = ImageStoryboard.instantiateViewController(withIdentifier: "IMAGESCOL") as! ImagesCollectionViewController
ImageController.RecivedData1 = media.bannerImages

These codes do nothing is expected, because you declare an ImageController , but you don't use/present it. 这些代码不会执行任何操作,因为您声明了ImageController ,但没有使用/展示它。

So, according to the context, I assume that you have a UITabBarController in Main.storyboard , and the UITabBarController has two UIViewController , and one is ImageController . 因此,根据上下文,我假设您在Main.storyboard有一个UITabBarController ,而UITabBarController有两个UIViewController ,其中一个是ImageController If I were right, you could try codes below: 如果我是对的,则可以尝试以下代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "IMAGEVID") as! UITabBarController

// You should access the `imageController` through your `tabBarController`, 
// not instantiate it from storyboard.
if let viewControllers = tabBarController.viewControllers, 
   let imageController = viewControllers.first as? ImageController {
    imageController.recivedData1 = media.bannerImages
}

navigationController?.pushViewController(tabBarController, animated: true)

Another suggestion is you should use camel case to name your properties. 另一个建议是,您应该使用驼峰式大小写来命名属性。 For more details, you can refer to this style guideline . 有关更多详细信息,您可以参考此样式指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM