我在表格视图中使用自定义单元格我有两个用于图标的标签(我使用字体中的图标),第二个是单元格的标题
我有一个来自字体的图标数组,我希望在每30秒后在标签中制作它们。
例如,我有一个图标数组(消息,脸书,推特,Instagram)。我想第一次在标签中取第一个数据,然后每30秒取一个标签。
socialIcon = ["\u{ea61}","\u{e8c7}","\u{e8c8}","\u{e324}"] // partage + facebook + tweeter + message
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "animate", userInfo: nil, repeats: true)
timer.fire()
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
/*let cell = UITableViewCell()
cell.textLabel?.text = "Stretch Header"
cell.selectionStyle = .None*/
// let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as! ParametreViewCell
let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ParametreViewCell
cell.iconLabel.font = UIFont(name:"innovi", size: 20)
cell.titleLabel.text = self.paramTable[indexPath.row]
if indexPath.row == 0
{
func animate()
{
UIView.transitionWithView(cell.iconLabel,
duration: 1.0,
options: [.CurveEaseInOut],
animations: { () -> Void in
if (self.counter < self.socialIcon.count)
{
self.counter += 1
cell.iconLabel.text = self.socialIcon[self.counter]
print (cell.iconLabel.text )
}
}, completion: nil)
}
}
else
{
cell.iconLabel.text = self.iconTable[indexPath.row]
}
return cell
}
答案 0 :(得分:0)
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ParametreViewCell
cell.iconLabel.font = UIFont(name:"innovi", size: 20)
cell.titleLabel.text = self.paramTable[indexPath.row]
if indexPath.row == 0
{
cell.iconLabel.text = self.socialIcon[0]
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: #selector(animate), userInfo: nil, repeats: true)
}
else
{
cell.iconLabel.text = self.iconTable[indexPath.row]
}
return cell
}
func animate() {
var indexPath = NSIndexPath.init(forRow: 0, inSection: 0)
if let ifExists = tableView.indexPathsForVisibleRows?.contains(indexPath)
where ifExists {
let customCell = tableView.cellForRowAtIndexPath(indexPath) as! ParametreViewCell
UIView.transitionWithView(customCell.iconLabel,
duration: 1.0,
options: [.CurveEaseInOut],
animations: { () -> Void in
if (self.counter < self.socialIcon.count )
{
customCell.iconLabel.text = self.socialIcon[self.counter]
self.counter += 1
}
else
{
self.counter = 0
}
}, completion: nil)
}
}