我有一個問題,更新UITableView
。我呼籲它的reloadData
方法,但cellForRowAtIndexPath
不會被調用。代碼:的UITableView不重新加載
//.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];
}
我UITableView
連接theTableView
在廈門國際銀行,我還設置它的delegate
和dataSource
到File's Owner
。
我使用ELCTextFieldCell
,它爲我提供了一個UITableViewCell
與UILabel
和UITextField
。我在單元格中插入了一些值,當鍵盤隱藏tableView時,它應該重新載入它的數據以在其中一個單元格中顯示正確的結果。我做了一些調試和計算的工作,因爲它應該,但該單元格不刷新(正如我前面提到的cellForRowAtIndexPath
方法沒有得到[self.theTableView reloadData]
後調用。
謝謝。
任何幫助,將不勝感激
EDIT
找到的,一個 「醜」 的解決方案。而不是調用
[self.theTableView reloadData];
的
我叫
[self.theTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:7 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
這是醜陋和硬編碼,這可能導致問題以後,如果我會添加更多的細胞或刪除一些,但它的作品。
還在尋找那個會用reloadData
方法
可以實現代碼如下實例爲null。那它不起作用。保持NSLog(@「theTableView%@」,theTableView);並檢查。 – Dee
你在哪裏分配內存到表格視圖? – rishi
@Dee它不是。如果我將它從屏幕上滾動並再次顯示,單元格將刷新。調試器在keyboradWillHide的第一行顯示如下:'(UITableView *)$ 7 = 0x079f3e00; contentOffset:{-0,-0}>'。所以我想這不是代碼中的@rishi –
Novarg