cellForRowAtIndexPath未被调用

Bat*_*nom 2 xcode objective-c uitableview

我有一个视图,以这种方式在顶部添加另一个视图:

- (void)showAreaEditView {

    NSLog(@"SHOWING AREA EDITOR VIEW");

    if (self.thisAreaEditorView == nil) {

        // Create View
        AreaEditorView *tmpViewController = [[AreaEditorView alloc] initWithNibName:@"AreaEditorView" bundle:nil];
        self.thisAreaEditorView = tmpViewController;
        [tmpViewController release];

        // Hide the back button
        self.thisAreaEditorView.navigationItem.hidesBackButton = YES;

    }

    self.thisAreaEditorView.myInspectionID = self.myInspectionID;
    self.thisAreaEditorView.loggedIn = loggedIn;
    self.thisAreaEditorView.loggedInGroup = loggedInGroup;

    // Slide view up

    [self.view addSubview:thisAreaEditorView.view];


    CGRect endFrame = CGRectMake(self.view.frame.size.width/2 - thisAreaEditorView.view.frame.size.width/2,
                                 self.view.frame.size.height/2 - thisAreaEditorView.view.frame.size.height/2, 
                                 thisAreaEditorView.view.frame.size.width, 
                                 thisAreaEditorView.view.frame.size.height);

    CGRect startFrame = endFrame; // offscreen source

    // new view starts off bottom of screen
    startFrame.origin.y += self.view.frame.size.height;
    self.thisAreaEditorView.view.frame = startFrame;

    // start the slide up animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.6];   
    thisAreaEditorView.view.frame = endFrame; // slide in
    [UIView commitAnimations];

}
Run Code Online (Sandbox Code Playgroud)

我相信你可以忽略幻灯片部分,我觉得addSubview是相关的.

然后在thisAreaEditor我有视图与表和按钮等.UITableView委托/数据源正常进入文件所有者.

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

    NSLog(@"numberOfRowsInSection returning %d", [tableData count]);
    [tableData count];

}
Run Code Online (Sandbox Code Playgroud)

此函数numberOfRowsInSection返回4

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    NSString *thisText =  [tableData objectAtIndex:indexPath.row];
    cell.textLabel.text = thisText;

    NSLog(@"looking at cell %d text:%@", indexPath.row, thisText);

    return cell;

}
Run Code Online (Sandbox Code Playgroud)

但是从不调用cellForRowAtIndexPath.

我在这里不知所措,我不知道它是如何工作得很好但是其中一个委托函数根本就没有被调用.

我试过[bigTable reloadData]等等,表永远不会被填充,也没有来自函数输出的日志.

提前致谢.

NJo*_*nes 9

您可能刚刚编辑了这个,如果是这样我很抱歉,但看起来您忘记返回tableData的计数.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"numberOfRowsInSection returning %d", [tableData count]);
    return [tableData count];
}
Run Code Online (Sandbox Code Playgroud)