Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义标签文本不';不显示在UITableViewCell上_Ios_Swift_Swift3 - Fatal编程技术网

Ios 自定义标签文本不';不显示在UITableViewCell上

Ios 自定义标签文本不';不显示在UITableViewCell上,ios,swift,swift3,Ios,Swift,Swift3,我有一个带有两个不同原型单元的表视图 第二个原型单元有一个自定义标签,但当我执行项目时,它什么也没有显示。文本在那里(我知道,因为它正在打印),但它没有出现 ->TableViewController: import UIKit 导入推特 类TweetInestableViewController:UITableViewController { 类Tweets2TableViewCell:UITableViewCell { } lazy var images: [MediaItem] =

我有一个带有两个不同原型单元的表视图

第二个原型单元有一个自定义标签,但当我执行项目时,它什么也没有显示。文本在那里(我知道,因为它正在打印),但它没有出现

->TableViewController:

import UIKit
导入推特

类TweetInestableViewController:UITableViewController {

类Tweets2TableViewCell:UITableViewCell {

}

lazy var images: [MediaItem] = []
lazy var userMentions: [Mention]? = []
lazy var hashtags: [Mention]? = []
lazy var urls: [Mention]? = []

var tweet: Twitter.Tweet?

private enum MentionTypes {
    case Images
    case Hashtags
    case Users
    case URLs
}

private var mentionsCollection: Dictionary<MentionTypes, Bool> = [
    MentionTypes.Images: false,
    MentionTypes.Hashtags: false,
    MentionTypes.Users: false,
    MentionTypes.URLs: false
]

private var sectionTypes: Dictionary<MentionTypes, Int?> = [
    MentionTypes.Images: nil,
    MentionTypes.Hashtags: nil,
    MentionTypes.Users: nil,
    MentionTypes.URLs: nil
]

override func numberOfSections(in tableView: UITableView) -> Int {
    var count = 0
    if !(tweet?.media.isEmpty)! {
        mentionsCollection[MentionTypes.Images] = true
        count += 1
    }
    if !(tweet?.hashtags.isEmpty)! {
        mentionsCollection[MentionTypes.Hashtags] = true
        count += 1
    }
    if !(tweet?.userMentions.isEmpty)! {
        mentionsCollection[MentionTypes.Users] = true
        count += 1
    }
    if !(tweet?.urls.isEmpty)! {
        mentionsCollection[MentionTypes.URLs] = true
        count += 1
    }
    return count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if mentionsCollection[MentionTypes.Images] == true {
            sectionTypes[MentionTypes.Images] = section
            mentionsCollection[MentionTypes.Images] = false
            return (tweet?.media.count)!
        } else if mentionsCollection[MentionTypes.Hashtags] == true {
            sectionTypes[MentionTypes.Hashtags] = section
            mentionsCollection[MentionTypes.Hashtags] = false
            return (tweet?.hashtags.count)!
        } else if mentionsCollection[MentionTypes.Users] == true {
            sectionTypes[MentionTypes.Users] = section
            mentionsCollection[MentionTypes.Users] = false
            return (tweet?.userMentions.count)!
        } else if mentionsCollection[MentionTypes.URLs] == true {
            sectionTypes[MentionTypes.URLs] = section
            mentionsCollection[MentionTypes.URLs] = false
            return (tweet?.urls.count)!
        }
    return 0
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    //let data = temp[indexPath.row][indexPath.section]
    let cell = tableView.dequeueReusableCell(withIdentifier: "TweetMention", for: indexPath)
    // Configure the cell...
    if let sec = sectionTypes[MentionTypes.Images], indexPath.section == sec {
        let image = tweet?.media[indexPath.row].url
        if let tweetMentionCell = cell as? TweetMentionsTableViewCell {
            tweetMentionCell.imageURL = image!
            return cell
        }
    }

   let cell2 = tableView.dequeueReusableCell(withIdentifier: "TweetMention2Cell", for: indexPath)

    if let sec = sectionTypes[MentionTypes.Hashtags], indexPath.section == sec {
        let hashtag = tweet?.hashtags[indexPath.row]
        if let tweetMentionCell = cell2 as? TweetMentions2TableViewCell {
            tweetMentionCell.hashtag = (hashtag?.keyword)!
        }
    } else if let sec = sectionTypes[MentionTypes.Users], indexPath.section == sec {
        let userMention = tweet?.userMentions[indexPath.row]
        if let tweetMentionCell = cell2 as? TweetMentions2TableViewCell {
            tweetMentionCell.userMention = (userMention?.keyword)!
        }
    } else if let sec = sectionTypes[MentionTypes.URLs], indexPath.section == sec {
        let url = tweet?.urls[indexPath.row]
        if let tweetMentionCell = cell2 as? TweetMentions2TableViewCell {
            tweetMentionCell.url = (url?.keyword)!
        }
    }

    return cell2
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    if let sec = sectionTypes[MentionTypes.Images], section == sec {
        return "Images"
    } else if let sec = sectionTypes[MentionTypes.Hashtags], section == sec {
        return "Hashtags"
    } else if  let sec = sectionTypes[MentionTypes.Users], section == sec {
        return "Users"
    } else if let sec = sectionTypes[MentionTypes.URLs], section == sec {
        return "URLs"
    }
    return nil
}


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let cell = sender as? TweetMentionsTableViewCell {
        if segue.identifier == "Show Image" {
            if let imageVC = segue.destination as? ImageViewController {
                imageVC.imageURL = cell.imageURL?.absoluteURL
                //imageVC.imageRatio = tweet?.media[0].aspectRatio
            }
        }
    }
        if let cell = sender as? TweetMentions2TableViewCell {
            if segue.identifier == "Show Text" {
                if let mentionsSTTVC = segue.destination as? MentionsSearchTweetTableViewController {
                    if let text = cell.mentLabel {
                        mentionsSTTVC.mentionToSearch = text.text!
                    }
                }
            }
    }
}

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
    if let cell = sender as? TweetMentions2TableViewCell {
        if (cell.url.contains("http")) {
            UIApplication.shared.open(NSURL(string: cell.url)! as URL)
            return false
        }
    }
    return true
}
import UIKit
@IBOutlet weak var mentLabel: UILabel!

var userMention = "" {
    didSet {
        updateUI(mentionType: 2)
    }
}
var hashtag = "" {
    didSet {
        updateUI(mentionType: 1)
    }
}
var url = "" {
    didSet {
        updateUI(mentionType: 3)
    }
}

func updateUI(mentionType: Int) {
    if mentionType == 1 {
        mentLabel.text = hashtag
    } else if mentionType == 2 {
        mentLabel.text = userMention
    } else if mentionType == 3 {
        mentLabel.text = url
    }
    print(mentLabel.text!)
}