V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Keita1314
V2EX  ›  iDev

如何动态地根据 json/xml 的描述来实现自定义 UITableViewCell?

  •  1
     
  •   Keita1314 · 2015-12-27 13:01:48 +08:00 · 1935 次点击
    这是一个创建于 3048 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一个 APP 里面有多个项目,一个项目对应着一个 UITableView,不同的项目有不同的 json/xml,这里 json/xml 是用来描述 UITableViewCell ,然后切换项目的时候根据 json/xml 来渲染 UITableViewCell.
    比如
    一个项目的 cell 可能是这样

    {
    "cell":{
    "a":1
    "c":2
    }
    }

    另一个项目可能是这样

    {
    "cell":{
    "d":2
    "f":4
    "g":1
    "h":1
    }
    }

    只涉及文字, cell 要展示的内容要完全依赖项目对应的 json/xml 的,应该怎么实现这个自定义 UITableViewCell ?

    8 条回复    2015-12-28 08:56:41 +08:00
    Keita1314
        1
    Keita1314  
    OP
       2015-12-27 13:03:44 +08:00
    @onevcat 邀请喵神~
    Sunnyyoung
        2
    Sunnyyoung  
       2015-12-27 14:05:33 +08:00 via iPhone
    好奇 b 和 e 去哪了
    Keita1314
        3
    Keita1314  
    OP
       2015-12-27 14:19:35 +08:00
    @Sunnyyoung 举例子而已,实际的意思就是 tableviewcell 里面的内容,比如标签有哪些,有多少个,是根据 json/xml 来获取的,我想了想感觉只有在 cellForRowAtIndexPath 里面动态加 view ,但又觉得这种效率会不会太低
    Sunnyyoung
        4
    Sunnyyoung  
       2015-12-27 14:30:47 +08:00 via iPhone
    @Keita1314 不知道你要渲染的内容仅仅是文字呢还是复杂的内容
    felixzhu
        5
    felixzhu  
       2015-12-27 14:51:23 +08:00
    类似 NimbusKit 的实现?
    Sunnyyoung
        6
    Sunnyyoung  
       2015-12-27 14:55:56 +08:00 via iPhone
    诶,楼主你的头像跟我的好配,哈哈
    txx
        7
    txx  
       2015-12-27 14:58:02 +08:00 via iPhone
    写一个渲染引擎啦...
    clangdiagnostic
        8
    clangdiagnostic  
       2015-12-28 08:56:41 +08:00   ❤️ 1
    ViewModel 可能是你需要的,在 ViewModel 中处理不同的 json/xml 产生的内容。当然了,这是在你的 Cell 的 View 是不变的情况下。需要变化的话还是不同项目分开写把。其他的方法看着都觉得麻烦
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   806 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:20 · PVG 06:20 · LAX 15:20 · JFK 18:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.