2011-12-02 110 views
1

我有一个观点,即增加了一个图在上面以这种方式:的cellForRowAtIndexPath不会被调用

- (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]; 

} 

我敢肯定,你可以忽略的滑动部分,我觉得addSubview是相关的。

然后在thisAreaEditor中,我使用表格和按钮等来查看视图。 UITableView委托/数据源将正常进入文件所有者。

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

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

} 

这个函数返回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; 

} 

不过的cellForRowAtIndexPath不会被调用。

我在这里不知所措,我不知道它如何看起来工作正常,但其中一个委托函数根本不会被调用。

我试过[bigTable reloadData]等等,表只是永远不会被填充,并没有日志从函数输出。

在此先感谢。

回答

8

你可能刚刚编辑过这个,如果是的话,我很抱歉,但看起来你忘了返回tableData的计数。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSLog(@"numberOfRowsInSection returning %d", [tableData count]); 
    return [tableData count]; 
} 
+0

哦,我的,你是对的。我错过了'numberOfRowsInSection'中的'return'。不能相信它那么简单,谢谢! – Batnom

+0

im在'numberOfRowsInSection'中使用switch语句来处理8个不同的部分。并忽略了不包括“return”这个词。有些问题可能很难解决。 – lizzy81

0

也许你没有将tableView委托设置为self或数据源为self。添加以下代码&看看现在的工作 -

[tableView setDelegate:self]; 
[tableView setDataSource:self]; 
在你的头文件

也继承这些代表 - UITableViewDelegate, UITableViewDataSource

@interface yourViewController: UIViewController <UITableViewDelegate, UITableViewDataSource> 

希望这有助于。

+0

不幸的是仍然无法正常工作。在'viewWillAppear'中,我调用'populateTableData'函数触发'[bigTable reloadData]',所以'titleForHeaderInSection'被调用(不返回任何内容),然后'numberOfRowsInSection'(返回4),就是这样。 – Batnom

3

看来你很想念UITableViewDelegate。

如果您使用Interface Builder,请右键单击表格视图插座并将delegatedatasource拖动到File's Owner

如果不使用Interface Builder添加这个,你初始化你的tableView

bigTable.delegate = self; 
bigTable.dataSource = self; 

记住要导入的UITableViewDelegate和UITableViewDataSource协议,就像Srikar说。

希望这是对任何帮助。

干杯!

0

这是一个较旧的链接,但我想更新此信息以解决我如何解决此问题。 对我来说,问题是数组填充表有0行,所以cellForRowAtIndexPath从未被调用过。 确保您用来填充表的数组中包含数据。

相关问题