请教如何看 iOS 开发文档,有带范的吗 - 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
tedd
V2EX    iDev

请教如何看 iOS 开发文档,有带范的吗

  •  
  •   tedd 2014-02-21 22:43:24 +08:00 4043 次点击
    这是一个创建于 4330 天前的主题,其中的信息可能已经有所发展或是发生改变。
    正在学习看iOS官方开发文档,但有点看不懂,还望得到大家的指点,举个具体例子吧,我一个UIViewController作为UITableView的Delegate,看到文档说到conform UITableViewDataSource必须实现的tableView:cellForRowAtIndexPath方法,链接到该方法(如下),除了知道需要return cell外,余下的要怎么实现呢?也没有实例参考,请问下一步方向应该是怎么做呢


    Asks the data source for a cell to insert in a particular location of the table view. (required)

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    Parameters
    tableView
    A table-view object requesting the cell.
    indexPath
    An index path locating a row in tableView.
    Return Value
    An object inheriting from UITableViewCell that the table view can use for the specified row. An assertion is raised if you return nil.

    Discussion
    The returned UITableViewCell object is frequently one that the application reuses for performance reasons. You should fetch a previously created cell object that is marked for reuse by sending a dequeueReusableCellWithIdentifier: message to tableView. Various attributes of a table cell are set automatically based on whether the cell is a separator and on information the data source provides, such as for accessory views and editing controls.

    Availability
    Available in iOS 2.0 and later.
    Declared In
    UITableView.h
    12 条回复    1970-01-01 08:00:00 +08:00
    alexrezit
        1
    alexrezit  
       2014-02-21 22:44:44 +08:00   1
    到下面找 sample.
    tedd
        2
    tedd  
    OP
       2014-02-21 22:46:16 +08:00
    @alexrezit 请问下面是指?我将那页文档翻到最后也没有范例
    alexrezit
        3
    alexrezit  
       2014-02-21 22:0:53 +08:00   1
    @tedd
    在 UITableView 的 reference 面搜 "Related Sample Code".
    tedd
        4
    tedd  
    OP
       2014-02-21 22:55:46 +08:00
    @alexrezit 感谢alexrezit!找到啦!这下好了
    iPandaios
        5
    iPandaios  
       2014-02-21 22:58:55 +08:00   1
    @protocol UITableViewDataSource<NSObject>

    @required

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

    @optional

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // Default is 1 if not implemented

    查看协议UITableViewDataSource,里面的关键字@required是必需要实现的,而@optional是非必需的
    tedd
        6
    tedd  
    OP
       2014-02-22 00:01:56 +08:00
    @iPandaios 这段代码清晰明了,请问是在哪里查到的呢


    @alexrezit 另外想再请问问两位,一般要从何处了解到要成为某个Object的代理,要服从哪些protocol呢?譬如拿UIViewController成为UITableView的代理,要服从UITableViewDelegate和UITableViewDataSource,如果我不知道的情况下,应该如何查看呢?
    vixvix
        7
    vixvix  
       2014-02-22 00:48:33 +08:00   1
    @tedd

    UITableView
    Overview
    ...
    A UITableView object must have an object that acts as a data source and an object that acts as a delegate; typically these objects are either the application delegate or, more frequently, a custom UITableViewController object. The data source must adopt the UITableViewDataSource protocol and the delegate must adopt the UITableViewDelegate protocol.
    ...
    zwzmzd
        8
    zwzmzd  
       2014-02-22 00:57:15 +08:00   1
    刚入门的时候开发者文档不那么好懂,建议弄个项目练练手,后面看文档就很自然了
    cielpy
        9
    cielpy  
       2014-02-22 01:10:51 +08:00   1
    delegate这个我刚入门的时候好长时间没搞懂(基础本身不好,见笑了),建议如果delegate这个不懂的话就先记住怎么用吧,比如要使用tableView,就必须实现tableView的dataSource,不实现就不能用。如果obj1成为obj2的delegate,想看obj1要服从哪些delegate的话,去obj2的类里找@protocol,都有写明。熟练了也可以自己写delegate,不过现在觉得单纯做回调的话,block似乎更方便些。
    qdvictory
        10
    qdvictory  
       2014-02-22 01:18:12 +08:00 via iPhone   1
    转来转去永远是文档和demo,头文件也可以参考。重要的还是熟能生巧
    laihj
        11
    laihj  
       2014-02-22 01:20:52 +08:00   1
    建议先看Guide,再看Class Referance,比较好懂
    tedd
        12
    tedd  
    OP
       2014-02-22 01:24:14 +08:00
    @vixvix 这就是我希望找的!再回头去看了看文档,这么重要的一段话居然在第五段...一来就说多好
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3123 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 28ms UTC 04:53 PVG 12:53 LAX 20:53 JFK 23:53
    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