IOS cellForRowAtIndexPath方法不被调用

来源:互联网 发布:python绝技 代码 下载 编辑:程序博客网 时间:2024/06/07 02:30

 问题:

        第一次进入可以调用,创建新的cell。

        从别的view跳转回来,就不在创建新的cell,不调用方法cellForRowAtIndexPath

        

@interface ScheduleTableViewController :UITableViewController 



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

    static NSString *customCellIndentifier =@"CustomCellIndentifier";

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:customCellIndentifier];

    

    //定义新的cell

    if(cell ==nil){

        //使用默认的UITableViewCell,但是不使用默认的imagetext,改为添加自定义的控件

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:customCellIndentifier];

   

 }    

    return cell;

}



解决方法:

- (void)viewDidLoad {

    

    [superviewDidLoad];

   //添加:

    self.tableView.delegate =self;

    self.tableView.dataSource =self;

    //cell显示不完整

    self.edgesForExtendedLayout =UIRectEdgeNone;

    [selfviewWillAppear:YES];

}


-(void)viewWillAppear:(BOOL)animated{

    [superviewWillAppear:animated];  

     self.automaticallyAdjustsScrollViewInsets =NO;

    //每次进入此页面都需要从数据库中读取数据显示在tableView

    self.listData=[NSMutableArrayarrayWithArray:[ScheduleDAOgetScheduleList]];

   //添加

    [self.tableViewreloadData];

    

}





0 0
原创粉丝点击