不调用CellForRowAtIndexPath

时间:2013-04-23 14:25:11

标签: iphone ios objective-c uitableview

我正在编写一个app hat,有很多视图,我使用了滑动视图库(ECSlidingViews)。问题是当我用对象填充数组并用tableView:cellForRowIndexPath:方法填充表中的对象时,它确实在表中显示数据,但是当我转到其他视图并返回时数据消失,因为{{ 1}}未被调用。这是代码:

tableView:cellForRowIndexPath:
当我回到具有表格视图的视图时,会调用

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"begin of cellForRowAtIndexPath"); SchedualeCell *cell = (SchedualeCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"]; Course *temp = [array objectAtIndex:indexPath.row]; cell.nameLb.text = temp.name; cell.hourLb.text = [NSString stringWithFormat:@"%d",temp.hour]; cell.startTimeLb.text = temp.startTime; cell.endTimeLb.text = temp.endTime; NSLog(@"End of cellForRowAtIndexPath"); return cell; } tableView:numberOfRowsInSection:

P.S。:视图是numberOfSectionsInTableView:,里面有表视图,我在发布问题之前搜索了所有StackOverflow。

编辑:这是我设置委托和数据源的地方

UIViewController

我确实在标题

中包含了委托和数据源
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"Did Appear");
    // Do any additional setup after loading the view.
    self.view.layer.shadowOpacity = 0.75f;
    self.view.layer.shadowRadius = 10.0f;
    self.view.layer.shadowColor= [UIColor blackColor].CGColor;

    if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]])
    {
        self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
    }
    [self.view addGestureRecognizer:self.slidingViewController.panGesture];

    if (array == nil)
    {
        array = [[NSMutableArray alloc]init];
    }

    table.delegate = self;
    table.dataSource = self;
    [table reloadData];

}

2 个答案:

答案 0 :(得分:4)

首先,它不是numberOfRowsAtSectionnumberOfTableView。它是numberOfSectionsInTableViewnumberOfRowsInSection

您可以做的事情:

1) NSLog您的numberOfRowsInSection。请注意,如果它为“0”,则永远不会调用cellForRowAtIndexPath

2)如果您在某些UITableView内使用UIView,则应添加:

[self.view addSubview:table];

3)不要忘记包括:

@interface yourViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

答案 1 :(得分:0)

检查您是否重新构建tableview中的ViewWillAppear。 有时,如果我们设置了帧,CellForRowAtIndexPath将不会调用。

相关问题