UITableView没有重新加载

时间:2012-06-19 06:33:55

标签: iphone objective-c uitableview

我在更新UITableView时遇到问题。我在其上调用了reloadData方法,但cellForRowAtIndexPath没有被调用。代码:

//.h
@interface MasterViewController : UIViewController<ELCTextFieldDelegate, UITableViewDelegate, UITableViewDataSource> {
  //some variables
}
@property (nonatomic, retain) IBOutlet UITableView *theTableView;
//other properties

//.m
- (void)viewDidLoad {
  //some code
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification {
  self.theTableView.frame = CGRectMake(0, 0, 320, 480 - 64);
  [self.theTableView reloadData];
}

我已将theTableView与xib中的UITableView相关联,我还将delegatedataSource设置为File's Owner

我使用ELCTextFieldCellUITableViewCell提供了UILabelUITextField。我在单元格中插入一些值,当键盘隐藏时,tableView应重新加载它的数据,以在其中一个单元格中显示正确的结果。我做了一些调试和计算工作,但是该单元格没有刷新(正如我所提到的,cellForRowAtIndexPath方法在[self.theTableView reloadData]之后没有被调用。

谢谢。

任何帮助将不胜感激

修改

为此找到了一个“丑陋”的解决方案。而不是打电话

[self.theTableView reloadData];

我致电

[self.theTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:7 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

这是丑陋和硬编码的,如果我要添加更多单元格或删除一些单元格,可能会导致以后出现问题,但它可以正常工作。

仍在寻找使用reloadData方法

的解决方案

3 个答案:

答案 0 :(得分:6)

reloadData重新显示可见行(效率)。您在reloadData之前设置tableview框架的事实让我认为tableview由于某种原因没有看到特定单元格在那时是可见的,因此它不会要求新的(和这解释了为什么在向下/向上滚动后正确刷新)。在调用reloadData[theTableView visibleCells];)之前,尝试轮询您的tableview以查看哪些报告为可见单元格。我希望这可以帮助您跟踪问题。

答案 1 :(得分:1)

只有在表格中有一些变化时才会重新加载表格。

答案 2 :(得分:0)

检查tableView是否为零...如果是,则分配内存

中返回的是什么
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

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

都返回非零值而非应该被称为

相关问题