如何动态地根据 json/xml 的描述来实现自定义 UITableViewCell? - V2EX
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 2462 次点击
    这是一个创建于 3628 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一个 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     Solana     3686 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 00:05 PVG 08:05 LAX 16:05 JFK 19:05
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86