我把控制器继承的父类从uiviewController 改成uitableviewController,然后把Main.storyboard原来的视图删掉,拖了个tableview的视图并绑定好我的控制器,然后把uitableviewdataSource协议中的必须实现方法声明,分别是
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
但到编译的时候,只有第一条方法执行了,而且还执行了两遍,第二条并不执行,有大神解答一下么

解决方案 »

  1.   

    numberOfRowsInSection才是required
    numberOfSectionsInTableView不是必须的
      

  2.   

    第二个方法是创建单元格时才会调用的方法,你没创建单元格,所以不会进入-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法之中
      

  3.   

    你设置rows了么?
      

  4.   

     numberOfSectionsInTableView 告诉 TableView 你有多少个 Section, numberOfRowsInSection告诉 TableView 你每个 Section 有多少行你只实现了 numberOfSectionsInTableView那就是说告诉了 TableView 有多少个 Section,但是没有告诉 TableView 有多少行,所以 TableView 就不知道有多少行了,默认应该是0行,那么0行代表一行都没有,那就不需要执行-(UITableViewCell*)tableView:cellForRowAtIndexPath:,所以这个方法就没有被调用了