问一个Container View的问题 - 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
chouti
V2EX    iDev

问一个Container View的问题

  •  
  •   chouti 2013-01-25 14:53:25 +08:00 4994 次点击
    这是一个创建于 4720 天前的主题,其中的信息可能已经有所发展或是发生改变。
    零基础自学iOS开发中,遇到一个难题不知道怎么解决,想来V2EX求教

    我有一个UIViewController(VC.h VC.m)在这个Controller中,我期望可以混合UIImage,UIText 和一个 Static Cells 的 Table View。因为 Static Cells 的 Table View 只能存在于 TableViewController 中,我在UIViewController里放了一个 Container View,这个 Container View 连接了一个 UITableViewController(TVC.h TVC.m)。

    在我的VC.h 中我声明了一个
    @property (nonatomic, strong) CHJItem *item;

    我希望在我的 TVC.m 中使用这个item,比如 self.presentingViewController.item.title 这样。

    可是,Xcode 提示我 Property 'item' not found on object of type 'UIViewController *'

    不知道这是为什么?如何解决这个问题?
    4 条回复    1970-01-01 08:00:00 +08:00
    diwup
        1
    diwup  
       2013-01-25 15:05:56 +08:00
    self.presentingViewController 的返回类型是 UIViewController. 在你的特殊情况里,这个 UIViewController 正好是你的 VC 类型。强转一下就好了。

    TC * myTC = (TC *)self.presentingViewController;
    myTC.item......
    alexrezit
        2
    alexrezit  
       2013-01-25 15:10:08 +08:00
    不知道我理解的对不对, 你只是想写一个内容固定的 table view 么?
    正常的思路应该是直接把 table view 作为 subview 加进去然后设置 table view 的 delegate 和 data source 为这个 view controller 吧?
    chouti
        3
    chouti  
    OP
       2013-01-25 15:31:29 +08:00
    @alexrezit 因为初学,我用的 Storyboad 来构建我的整个UI,遇到UIViewController中不能加入Static Cells的TableView之后,我就选择了用Container View来嵌入。

    我的整个界面大致如图所示

    https://www.dropbox.com/s/w4fcu7o0tredlzf/Photo%2013-1-25%2015%2020%2001.jpg

    我会试试用你的思路来改一下。谢谢。
    alexrezit
        4
    alexrezit  
       2013-01-25 15:37:59 +08:00   1
    @chouti
    我建议你直接拖一个 UITableView 上去, 然后把 delegate 和 dataSource 指向那个 view controller, 然后在 view controller 内用代码实现. Storyboard 看起来很美, 可实际上比用 xib 更难操作, 当然绝不仅仅是占用更多屏幕空间的问题. 而用 IB 图形化实现界面的过程实际上也只是类似于 NSCoding 而已.
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2683 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 09:24 PVG 17:24 LAX 01:24 JFK 04:24
    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