ios - swift3中字符串转成方法的时候,怎么接收返回值?
阿神
阿神 2017-04-18 09:50:09
[iOS讨论组]

核心代码如下

var tweakEntries = [(title : String, array : [Array<String>])]()

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.tableFooterView = UIView()
    navigationItem.title = "设置"
    //tableView.separatorStyle = .none

    let timeSettingArr = [
        ["工作时间间隔","workTime","setWorkTime"],
        ["休息时间间隔","relaxTime","setRelaxTime"],
    ]
    let _ = [
        ["通知标题","",""],
        ["通知语","",""]
    ]
    let _ = [
        ["显示背景图片","displayStatus","setDisplayStatus"]
    ]
    tweakEntries = [
        ("时间设置",timeSettingArr),
        //("通知设置",localNoti),
        //("其他设置",otherSettingArr)
    ]
}



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let section = indexPath.section
    let row = indexPath.row
    let identifier  = "SettingCell"
    var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
    if (cell == nil) {
        cell = SettingCell.init(style: .subtitle, reuseIdentifier: identifier)
    }
    cell?.textLabel?.text = tweakEntries[section].array[row][0]
    let methodName = tweakEntries[section].array[row][1];
    print("\(methodName)")
    let method : Selector = Selector(methodName)
    let detailText = perform(method)
    //let temp : CGFloat = detailText as! CGFloat
    //cell?.detailTextLabel?.text = "\(temp)"


    return cell!
}

func workTime() -> CGFloat {
    return 11.0
}

怎么接收 workTime () -> CGFloat 这个方法的返回值
看到perform 的返回值是 Unmanaged<AnyObject>!,不用 perform 的话还有其他相同功能的方法么?
public func perform(_ aSelector: Selector!) -> Unmanaged<AnyObject>!

下面是全部代码
code: https://github.com/CoderYLZha...

http://stackoverflow.com/ques...

阿神
阿神

闭关修行中......

全部回复(1)
黄舟

不知道为什么,总感觉你这样做是anti-pattern的。

不过提供一个古老的思路:把储存结果的变量当指针传进去。

func workTime() -> CGFloat {
   let temp : CGFloat
   /* 具体的操作 */
   return temp
}

改成:

func workTime(inout result: CGFloat) -> void {
   let temp : CGFloat
   /* 具体的操作 */
   result = temp
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号