正如标题所示,我遇到了一个小问题。这是我的代码:
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调用方法给我一个错误"无关参数标签'字符串'在调用"。下面是我的代码:
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:我刚刚修改了一个小错误,但是,但仍然不工作…
您忘记访问sharedInstance
:
InterfaceManager.sharedInstance.chooseAttributedString(squadra.nome, font: UIFont(name: "Noteworthy-Light", size: 23)!, color: UIColor.whiteColor())