Singleton中的func不起作用

时间:2015-08-21 21:18:59

标签: swift singleton uifont nsmutableattributedstring

正如标题所暗示的那样,我发生了一个单身人士的小问题。这是我的代码:

    import UIKit

class InterfaceManager: NSObject
{
    class var sharedInstance: InterfaceManager
    {
        get
        {
            struct Static
            {
            static var instance: InterfaceManager? = nil
            static var token: dispatch_once_t = 0
            }
            dispatch_once(&Static.token) { Static.instance = InterfaceManager()
            }
            return Static.instance!
        }
    }

    func chooseAttributedString(string: NSString, font: UIFont, color: UIColor)
    {
        let string: NSString = string
        var stringMutable = NSMutableAttributedString()
        stringMutable = NSMutableAttributedString(string: string as String , attributes: [NSFontAttributeName: font, NSForegroundColorAttributeName: color])
    }
}

但是当我要在类Xcode中调用该方法时,会给我一个错误"无关的参数标签' string'在电话"。按照我的行代码:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CellSquadreController
        let squadra = DataManager.sharedInstance.arrayCori[indexPath.row]

        cell.backgroundColor = UIColor.clearColor()
        cell.nomeSquadra.attributedText = InterfaceManager.sharedInstance.chooseAttributedString(string: squadra.nome, font: UIFont(name: "Noteworthy-Light", size: 23)!, color: UIColor.whiteColor())
        return cell
    }
PS:我刚刚修改了一个小错误,但是它仍然没有用......

1 个答案:

答案 0 :(得分:0)

您忘记访问sharedInstance

InterfaceManager.sharedInstance.chooseAttributedString(squadra.nome, font: UIFont(name: "Noteworthy-Light", size: 23)!, color: UIColor.whiteColor())