簡體   English   中英

在tableView reloadData上未調用cellForRowAtIndexPath

[英]cellForRowAtIndexPath not being called on tableView reloadData

我在一個視圖上有一個UITableView,該視圖在應用程序啟動時加載數據,然后稍后當用戶在框中輸入文本並單擊按鈕時,我重新查詢數據庫,重新填充存儲NFSutableArray的原始NSMutableArray。表的數據。

所有這些都運行良好。 在某些日志記錄語句中,我可以說出數組具有正確的信息,numberOfRowsInSection方法返回正確的計數,並在調用重載后被調用。

但是,永遠不會第二次調用cellForRowAtIndexPath(在重新加載之后),並且永遠不會更新表數據。

我已經花了幾個小時在網上搜索,但沒有發現任何有用的信息。 有人可以幫忙嗎?

所有代碼位於: http : //github.com/botskonet/inmyspot

具體的重載在以下位置調用: http : //github.com/botskonet/inmyspot/blob/master/Classes/InMySpotViewController.m

粗線94

來自: http : //github.com/botskonet/inmyspot/blob/master/Classes/PlateFormViewController.m

粗線101

更多信息:將新數據添加到mutablearray中后,如果我嘗試開始滾動表,它將最終死於:

“由於未捕獲的異常'NSRangeException'而終止應用程序,原因:'***-[NSCFArray objectAtIndex:]:索引(29)超出范圍(29)”'”

我認為這意味着表單元格無法在數組中找到任何數據來匹配滾動位置,這似乎是因為數組具有新數據,而表卻沒有。

我看到了同樣的問題。 我的問題很相似:我有一個UIViewController子類(MyViewController) ,其中包含一些內容,包括對我的UITableViewController (MyTableViewController)子類UITableViewController (MyTableViewController)的引用。 MyViewController.xib ,為了確保由MyViewController加載的tableView與在MyTableViewController加載的tableView相同,在接口生成器中,我從MyViewController的tableView中引用了該引用,並使其指向MyTableViewController's視圖。屬性。

這是一張圖片,因為Interface Builder中的動作很難描述: 在此處輸入圖片說明

由於尚未正確設置UITableView的委托,因此未調用您的重新加載。

@interface InMySpotViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
}

您還可以在此處覆蓋mainDelegate.plates:

NSMutableArray *platesArray = [[NSMutableArray alloc] init];
                mainDelegate.plates = platesArray;
                [platesArray release];

為什么不合並兩個控制器。 您的操作方式會導致大多數問題。 您不必要在PlateFormViewController中創建一個新的InMySpotViewController。

plateLookup ,破壞現有數組:

    NSMutableArray *platesArray = [[NSMutableArray alloc] init];
    mainDelegate.plates = platesArray;
    [platesArray release];

此后,您重新加載表。 該數組有零個元素,因此從不調用cellForRowAtIndexPath:

編輯:您還創建一個新的視圖控制器

        InMySpotViewController *viewController = [[InMySpotViewController alloc] init]; 
        [viewController refreshTable];

因此,您甚至不需要重新加載屏幕上可見的表。

由於家庭成員進行了調試,我確定了導致以下問題的原因:

inMySpotViewController設置為UITableViewController而不是UIViewController ,這就是表格掩蓋其他所有內容的原因。 我將其更改為UIViewController ,然后添加了新的UITableView

IBOutlet UITableView *myTblView;
@property (nonatomic, retain) UITableView *myTblView;

然后在整個代碼中引用該表視圖。 該代碼是在單視圖分支上完成的,因此現在可以正常工作。

PlatesArray一直被認為是一個問題,但這不是因為越界越好是因為數組已成功更新,而表視圖卻沒有(所以我試圖滾動到數組中沒有索引的索引存在,但我知道這是問題所在,因為它們的表沒有進行視覺更新)。

重寫值后,我已經成功注銷了修改后的Plates數組的內容,並且它們都是正確的,而Plates.count返回的是正確的值,因此無論如何它都不會變得“混亂”。

謝謝大家的幫助!

我有同樣的問題。 谷歌的大多數答案都談到了delegate 但是我確定我的delegatedata source設置正確。

后來,我發現問題在於此方法的返回值:

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

在我的代碼中,我重寫了如下方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return _dataArray.count;
}

但是當檢查此斷點時,我發現_dataArray存在。 此方法應返回一個正整數,否則

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

可能不會被調用。

希望對您有所幫助。

我遇到了同樣的問題,並且我追蹤到它在接口中具有tableView屬性。 我不認為我自己添加了這個,但誰在乎,它掩蓋了UITableViewController自己的tableView屬性。 我將其刪除,該項目繼續構建,但是現在當我從推入的viewcontroller返回第一個UITableViewController時,會發生正確的順序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM