Nov*_*arg 1 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];
}
Run Code Online (Sandbox Code Playgroud)
我连接theTableView与UITableView在厦门国际银行,我还设置它的delegate和dataSource来File's Owner.
我使用ELCTextFieldCell它为我提供了UITableViewCella UILabel和a UITextField.我在单元格中插入一些值,当键盘隐藏时,tableView应重新加载它的数据,以在其中一个单元格中显示正确的结果.我做了一些调试和计算工作,但是那个单元格没有刷新(正如我之前提到的那样,cellForRowAtIndexPath方法不会被调用[self.theTableView reloadData].
谢谢.
任何帮助,将不胜感激
编辑
找到了一个"丑陋"的解决方案.而不是打电话
[self.theTableView reloadData];
Run Code Online (Sandbox Code Playgroud)
我打了电话
[self.theTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:7 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
Run Code Online (Sandbox Code Playgroud)
它是丑陋的和硬编码的,如果我将添加更多单元格或删除一些单元格,可能会导致以后出现问题,但它有效.
仍在寻找可以使用reloadData方法的解决方案
reloadData重新显示仅可见的行(为了提高效率).你之前设置tableview框架的事实reloadData使我认为tableview由于某种原因没有看到特定单元格在那时是可见的,所以它不会要求一个新的(这解释了为什么在滚动之后)向下/向上刷新正确).尝试轮询您的tableview,以便在调用reloadData([theTableView visibleCells];)之前查看哪些报告为可见单元格.我希望这可以帮助您跟踪问题.