Use TableView without TableView Delegate or DataSource

Discussion in 'iOS Programming' started by mikezang, Dec 14, 2010.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I am using a UIViewController with UITableView, it works good, I didn't define <UITableViewDelegate> or <UITableViewDataSource>, but I can use all methods of delegate and data resource.
    I tried to find why I can use them, no result, can you tell me the simple reason, why?

    Code:
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
    
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    The code works because the runtime successfully finds the required selectors.

    The compiler has not been told that the class is compliant with the required protocols, and so you will see the warnings of the following form:

    Code:
    /path/to/Classes/RootViewController.m:89:0 /path/to/Classes/RootViewController.m:89: warning: class 'RootViewController' does not implement the 'UITableViewDelegate' protocol
    
     
  3. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    The problem looks like ther is no such warning...
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    You probably only get the warning if you set the table's delegate and datasource in code. If you set it in IB then I think there will be no warning.
     

Share This Page