2012-06-19 49 views
1

我有一個問題,更新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在廈門國際銀行,我還設置它的delegatedataSourceFile's Owner

我使用ELCTextFieldCell,它爲我提供了一個UITableViewCellUILabelUITextField。我在單元格中插入了一些值,當鍵盤隱藏tableView時,它應該重新載入它的數據以在其中一個單元格中顯示正確的結果。我做了一些調試和計算的工作,因爲它應該,但該單元格不刷新(正如我前面提到的cellForRowAtIndexPath方法沒有得到[self.theTableView reloadData]後調用。

謝謝。

任何幫助,將不勝感激

EDIT

找到的,一個 「醜」 的解決方案。而不是調用

[self.theTableView reloadData]; 

我叫

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

這是醜陋和硬編碼,這可能導致問題以後,如果我會添加更多的細胞或刪除一些,但它的作品。

還在尋找那個會用reloadData方法

+0

可以實現代碼如下實例爲null。那它不起作用。保持NSLog(@「theTableView%@」,theTableView);並檢查。 – Dee

+0

你在哪裏分配內存到表格視圖? – rishi

+0

@Dee它不是。如果我將它從屏幕上滾動並再次顯示,單元格將刷新。調試器在keyboradWillHide的第一行顯示如下:'(UITableView *)$ 7 = 0x079f3e00 ; contentOffset:{-0,-0}>'。所以我想這不是代碼中的@rishi – Novarg

回答

6

reloadData重新顯示只有可見行(效率)。您剛纔reloadData之前設置你的tableview的框架,這一事實讓我覺得,由於某種原因,tableview中沒有看到特定的細胞在當時是可見的,所以它不會對一個新的要求(這解釋了爲什麼後向下滾動/向上刷新正確)。嘗試輪詢您的tableview看到之前調用reloadData[theTableView visibleCells];)什麼報告爲可見的細胞。我希望這能幫助你跟蹤問題。

+1

謝謝!這正是發生的事情。在鍵盤仍然可見的情況下,tableView變得越來越大,可以拍攝整個屏幕。因此應該更新的單元格被鍵盤覆蓋。只是將'UIKeyboardWillHideNotification'更改爲'UIKeyboardDidHideNotification',現在它就像一個魅力一樣。 – Novarg

0

檢查tableView不爲零的解決方案......如果是這樣分配的內存

什麼是在

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

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

比都返回非零值它應該被稱爲只有當u有在表中的一些變化

+0

他們分別返回1和8,因爲它應該是 – Novarg

+0

上面的方法被調用?然後檢查你是否有連接數據源和委託出口連接到類和你的類聲明

+0

也檢查上述兩種方法不會錯誤地互換...只是猜測... –

1

表被重新加載.....

+0

正在修改用作數據源的字典 – Novarg

+0

當您運行第一次您的項目時,您是否正在獲取數據表 – Rajneesh071

+0

nope,當我啓動應用程序時tableView爲空 – Novarg