小编Fac*_*ose的帖子

将数据从TableView发送到DetailView Swift

我试图为我做一个最简单和最令人困惑的事情,直到现在我想开发自己的应用程序,为了做到这一点,我需要能够传递一些信息,具体取决于用户点击哪一行(它是Swift lenguage)

我们有一个RootViewController(表视图)和一个DetailViewController(带有1个标签和1个图像) 在此输入图像描述

(我们的观点)

这是代码:

@IBOutlet weak var tableView: UITableView!


var vehicleData : [String] = ["Ferrari 458" , "Lamborghini Murcielago" , "Bugatti Veyron", "Mercedes Benz Biome"]

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    var nib = UINib(nibName: "TableViewCell", bundle: nil)

    tableView.registerNib(nib, forCellReuseIdentifier: "cell")



}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return vehicleData.count
}



func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


    let cell:TableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") …
Run Code Online (Sandbox Code Playgroud)

tableview detailview swift

19
推荐指数
1
解决办法
5万
查看次数

将数据从tableView传递到Swift中的ViewController

我有一个应用程序,我正在尝试完全适应我想要的

我一直在关注Seemu Apps的Youtube教程,但是我需要添加一个可选的ViewController来完成它

这个应用程序有2个tableViews显示车辆,如果我们点击第一个tableView的一行,然后第二个tableView将显示所选车辆的列表.

这是我们到现在为止所拥有的:(图片链接,因为我在stackOverFlow上没有得到十分的声誉)

http://subefotos.com/ver/?65ba467040cb9280e8ec49644fd156afo.jpg

一切都运行完美,但我希望能够在可选的detailViewController中显示信息(带有每个车辆的详细描述的标签和更大的图像),具体取决于我们在secondTableViewControlle(或应用程序中的modelViewController)中单击的车辆究竟我是如何在tableViews之间的教程中遵循的

我知道我们需要通过prepareForSegue方法传递数据,我已经理解了这在制作教程中的步骤但我们有2个tableviewControllers

例如:如果我们想要显示最后一个viewController,其中包含法拉利458的信息以及这款车的精彩图片

我们需要做些什么才能显示每辆车的信息?

PD:我是编程领域的初学者,也许我需要以非常简单的方式看待它

整个代码:

ViewController.swift

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

     var selMake = String()

     @IBOutlet var tableView : UITableView!

    var transportData : [String] = ["Car", "Plane", "Motorcycle", "Truck" , "Train", "Bicycle" , "Helicopter"]

    //////////////////////////////////////////

    //viewDidLoad    
    override func viewDidLoad() {
        super.viewDidLoad()
        //Register custom cell

        var nib = UINib(nibName: "customCell", bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: "cell")
    }

    //Numbers of rows in Section        
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return …
Run Code Online (Sandbox Code Playgroud)

tableview swift

8
推荐指数
1
解决办法
2万
查看次数

共享按钮在 iPhone 上完美运行,但在 iPad 上崩溃

我正在尝试添加一个按钮,以便在 Twitter、Facebook 等中分享一些句子。它适用于所有 iPhone 型号,但模拟器在 iPad 上崩溃。

这是我的代码:

@IBAction func shareButton(sender: AnyObject) {

    frase = labelFrases.text!
    autor = labelAutores.text!


    var myShare = "\(frase) - \(autor)"

    let activityVC: UIActivityViewController = UIActivityViewController(activityItems: [myShare], applicationActivities: nil)



    self.presentViewController(activityVC, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

这是错误:

由于未捕获的异常“NSGenericException”而终止应用程序,原因:“UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7c0f9190>) 应该在演示发生之前设置一个非零的 sourceView 或 barButtonItem

我该如何解决?谢谢

social share swift

2
推荐指数
1
解决办法
2362
查看次数

标签 统计

swift ×3

tableview ×2

detailview ×1

share ×1

social ×1