Błąd twierdzenia w dequeueReusableCellWithIdentifier:forIndexPath:

Więc robiłem czytnik rss dla mojej szkoły i skończyłem kod. Przeprowadziłem test i dał mi ten błąd. Oto kod, do którego się odnosi:

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = 
     [tableView dequeueReusableCellWithIdentifier:CellIdentifier 
                                     forIndexPath:indexPath];
    if (cell == nil) {

        cell = 
         [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  
                                reuseIdentifier:CellIdentifier];

    }

Oto błąd na wyjściu:

2012-10-04 20:13:05.356 czytelnik [4390: c07] * awaria twierdzenia w -[UITableView dequeueReusableCellWithIdentifier: forIndexPath:], / SourceCache/UIKit_Sim/UIKit-2372 / UITableView.m:4460 2012-10-04 20: 13: 05.357 czytelnik[4390: c07] * Kończenie aplikacji z powodu braku exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell-must register a nib or a class dla Identyfikatora lub podłączyć komórkę prototypu w storyboardzie" * stos wywołań pierwszego rzutu: (0x1c91012 0x10cee7e 0x1c90e78 0xb64f35 0xc7d14 0x39ff 0xd0f4b 0xd101f 0xb980b 0xca19b 0x6692d 0x10e26b0 0x228dfc0 0x228233c 0x228deaf 0x1058cd 0x4e1a6 0x4ccbf 0x4cbd9 0x4be34 0x4bc6e 0x4ca29 0x4f922 0xf9fec 0x46bc4 0x47311 0x2cf3 0x137b7 0x13da7 0x14fab 0x26315 0x2724b 0x18cf8 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x147da 0x1665c 0x2a02 0x2935) libc++abi.dylib: terminate wywołane wyrzuceniem wyjątku

A oto kod, który wyświetla się na ekranie błędu:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
Proszę o pomoc!
Author: Erik Godard, 2012-10-05

20 answers

Używasz metody dequeueReusableCellWithIdentifier:forIndexPath:. Dokumentacja dla tej metody mówi tak:

Ważne: przed wywołaniem tej metody musisz zarejestrować klasę lub plik nib przy użyciu metody registerNib:forCellReuseIdentifier: lub registerClass:forCellReuseIdentifier:.

Nie zarejestrowałeś stalówki ani klasy dla identyfikatora ponownego użycia "Cell".

Patrząc na Twój kod, wydaje się, że spodziewasz się, że metoda dequeue zwróci nil, jeśli nie ma komórki do podania. Musisz użyć dequeueReusableCellWithIdentifier: do tego zachowanie:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

Zauważ, że dequeueReusableCellWithIdentifier: i dequeueReusableCellWithIdentifier:forIndexPath: są różnymi metodami. Zob. doc dla pierwszego i drugiego .

Jeśli chcesz zrozumieć, dlaczego chcesz kiedykolwiek użyć dequeueReusableCellWithIdentifier:forIndexPath:, sprawdź to Q & A .

 479
Author: rob mayoff,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:26:19

Myślę, że ten błąd dotyczy rejestracji Twojej stalówki lub klasy dla identyfikatora.

Aby zachować to, co robisz w funkcji tableView:cellForRowAtIndexPath i po prostu dodać poniższy kod do swojego viewDidLoad:

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
U mnie działa. Mam nadzieję, że to pomoże.
 137
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-13 09:42:13

Chociaż to pytanie jest dość stare, istnieje inna możliwość: Jeśli używasz Storyboardów, po prostu musisz ustawić Cell identifier w Storyboardzie.

Więc jeśli twoim CellIdentifier jest "Cell", ustaw właściwość" Identifier": Tutaj wpisz opis obrazka

Upewnij się, że po tym wyczyścisz swoją konstrukcję. XCode czasami ma problemy z aktualizacjami Storyboard

 66
Author: Sebastian Borggrewe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-18 15:36:17

Miałem ten sam problem zamiany na

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

   if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    }

Rozwiązany

 59
Author: iMeMyself,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-26 06:24:31

Problem jest najprawdopodobniej dlatego, że konfigurujesz niestandardowe UITableViewCell w storyboardzie, ale nie używasz storyboardu do tworzenia instancji UITableViewController, która używa tego UITableViewCell. Na przykład w MainStoryboard masz podklasę UITableViewController o nazwie MyTableViewController i niestandardową dynamikę UITableViewCell o nazwie MyTableViewCell o identyfikatorze "MyCell".

Jeśli stworzysz swój własny UITableViewController w ten sposób:

 MyTableViewController *myTableViewController = [[MyTableViewController alloc] init];

Nie zarejestruje automatycznie Twojego niestandardowego tableviewcell dla Ciebie. Musisz ręcznie zarejestrować to.

Ale jeśli używasz storyboard do tworzenia instancji MyTableViewController, w ten sposób:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyTableViewController *myTableViewController = [storyboard  instantiateViewControllerWithIdentifier:@"MyTableViewController"];

Nice thing happens! UITableViewController automatycznie zarejestruje Twoją niestandardową komórkę tableview, którą zdefiniujesz w storyboard.

W metodzie delegata "cellForRowAtIndexPath" możesz utworzyć komórkę widoku tabeli w następujący sposób:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

//Configure your cell here ...

return cell;
}

DequeueReusableCellWithIdentifier automatycznie utworzy nową komórkę dla Ciebie, jeśli nie ma komórki wielokrotnego użytku dostępnej w recyklingu Kolejka

Więc jesteś skończony!
 25
Author: James Wang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-04 13:48:22

Dodam tylko, że Xcode 4.5 zawiera nowy dequeueReusableCellWithIdentifier:forIndexPath:
w domyślnym kodzie szablonu-potencjalny klient dla programistów oczekujących starszej metody dequeueReusableCellWithIdentifier:.

 19
Author: Brian Shriver,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-29 19:31:48

W swoim storyboardzie powinieneś ustawić "identyfikator" prototypowej komórki na taki sam, jak "komórka" CellReuseIdentifier. Wtedy nie otrzymasz tej wiadomości lub musisz wywołać tę funkcję registerClass:.

 18
Author: Steven,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-03 23:43:44

Swift 2.0 rozwiązanie:

Musisz wejść do Inspektora atrybutów i dodać nazwę identyfikatora komórki:

Tutaj wpisz opis obrazka

Następnie musisz dopasować swój IDENTYFIKATOR do dequeue w następujący sposób:

let cell2 = tableView.dequeueReusableCellWithIdentifier("ButtonCell", forIndexPath: indexPath) as! ButtonCell

Alternatywnie

Jeśli pracujesz z nib, być może będziesz musiał zarejestrować swoją klasę w cellForRowAtIndexPath:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {       

    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "SwitchCell")

    // included for context            
    let cell = tableView.dequeueReusableCellWithIdentifier("SwitchCell", forIndexPath:indexPath) as! SwitchCell

    //... continue    
}

Apples ' s UITableView Class Reference mówi:

Przed usuwanie dowolnych komórek, wywołanie tej metody lub registerNib: forCellReuseIdentifier: metoda wskazująca widok tabeli w jaki sposób aby utworzyć nowe komórki. Jeśli komórka określonego typu nie jest aktualnie w kolejce ponownego użycia widok tabeli wykorzystuje podane informacje do automatycznie utwórz nowy obiekt komórki.

Jeśli wcześniej zarejestrowałeś plik klasy lub nib z tym samym ponownym użyciem identyfikator, Klasa określona w parametrze cellClass zastępuje stary wpis. Możesz podać nil Dla cellClass jeśli chcesz Wyrejestruj klasę z podanego identyfikatora ponownego użycia.

Oto kod z Apples Swift 2.0 framework:

// Beginning in iOS 6, clients can register a nib or class for each cell.
// If all reuse identifiers are registered, use the newer -dequeueReusableCellWithIdentifier:forIndexPath: to guarantee that a cell instance is returned.
// Instances returned from the new dequeue method will also be properly sized when they are returned.

@available(iOS 5.0, *)
func registerNib(nib: UINib?, forCellReuseIdentifier identifier: String)

@available(iOS 6.0, *)
func registerClass(cellClass: AnyClass?, forCellReuseIdentifier identifier: String)
 17
Author: Dan Beaulieu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-21 01:08:21

Jeśli wybierasz niestandardowe komórki statyczne po prostu skomentuj tę metodę:

//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    static NSString *CellIdentifier = @"notificationCell";
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//    return cell;
//}

I nadaj komórkom identyfikator w "Inspektor atrybutów" w storyboard.

 3
Author: Francisco Gutiérrez,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-05 04:52:06

Dam ci odpowiedź zarówno w Objective C, jak i Swift.Przed tym chcę powiedzieć

Jeśli używamy dequeueReusableCellWithIdentifier:forIndexPath:,musimy zarejestrować klasę lub plik nib używając metody registerNib:forCellReuseIdentifier: lub registerClass: forCellReuseIdentifier: przed wywołaniem tej metody jako Apple Mówi

Więc dodajemy registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier:

Po zarejestrowaniu klasy dla podanego identyfikatora i utworzeniu nowej komórki ta metoda inicjalizuje komórka poprzez wywołanie metody initWithStyle: reuseIdentifier:. W przypadku komórek opartych na stali nib metoda ta ładuje obiekt cell z dostarczonego pliku nib. Jeśli istniejąca komórka była dostępna do ponownego użycia, ta metoda wywoła zamiast niej metodę preparedforreuse komórki.

W metodzie viewDidLoad powinniśmy zarejestrować komórkę

Objective C

Opcja 1:

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

Opcja 2:

[self.tableView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"cell"];

W powyższym kodzie nibWithNibName:@"CustomCell" podaj swoją nazwę stalówki zamiast mojej stalówka Nazwa CustomCell

SWIFT

Opcja 1:

tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

Opcja 2:

tableView.registerNib(UINib(nibName: "NameInput", bundle: nil), forCellReuseIdentifier: "Cell") 

W powyższym kodzie nibName:"NameInput" podaj nazwę stalówki

 3
Author: user3182143,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-23 06:34:26

Spędziłem wczoraj wiele godzin, zastanawiając się, dlaczego moja wygenerowana programowo tabela zawiesiła się na [mytable setDataSource: self]; komentowanie i wyskakiwanie pustej tabeli było OK, ale zawieszało się za każdym razem, gdy próbowałem dotrzeć do datasource;

Miałem delegację ustawioną w pliku h: @ interface myViewController: UIViewController

Miałem kod źródłowy danych w mojej implementacji i nadal bum!, crash every time! Podziękowania dla " xxd "(nr 9): dodanie tej linijki kodu rozwiązało dla mnie! W rzeczywistości uruchamiam tabelę z przycisku IBAction, więc oto mój pełny kod:

    - (IBAction)tapButton:(id)sender {

    UIViewController* popoverContent = [[UIViewController alloc]init];

    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
    popoverView.backgroundColor = [UIColor greenColor];
    popoverContent.view = popoverView;

    //Add the table
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)         style:UITableViewStylePlain];

   // NEXT THE LINE THAT SAVED MY SANITY Without it the program built OK, but crashed when      tapping the button!

    [table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    table.delegate=self;
    [table setDataSource:self];
    [popoverView addSubview:table];
    popoverContent.contentSizeForViewInPopover =
    CGSizeMake(200, 300);

    //create a popover controller
    popoverController3 = [[UIPopoverController alloc]
                          initWithContentViewController:popoverContent];
    CGRect popRect = CGRectMake(self.tapButton.frame.origin.x,
                                self.tapButton.frame.origin.y,
                                self.tapButton.frame.size.width,
                                self.tapButton.frame.size.height);


    [popoverController3 presentPopoverFromRect:popRect inView:self.view   permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];



   }


   #Table view data source in same m file

   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
   {
    NSLog(@"Sections in table");
    // Return the number of sections.
    return 1;
   }

   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
  {
    NSLog(@"Rows in table");

    // Return the number of rows in the section.
    return myArray.count;
   }

   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath
    {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    NSString *myValue;

    //This is just some test array I created:
    myValue=[myArray objectAtIndex:indexPath.row];

    cell.textLabel.text=myValue;
    UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 12.0 ];
    cell.textLabel.font  = myFont;

    return cell;
   }

Przy okazji: przycisk musi być połączony jako IBAction i jako iboutlet, jeśli chcesz zakotwiczyć wyskakujące do niego.

Uipopovercontroller * popoverController3 jest zadeklarowany w pliku H bezpośrednio po interfejsie @pomiędzy {}

 2
Author: Simone,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-17 09:54:23

FWIW, mam ten sam błąd, gdy zapomniałem ustawić identyfikator komórki w storyboardzie. Jeśli jest to twój problem, to w storyboardzie kliknij komórkę widoku tabeli i ustaw identyfikator komórki w edytorze atrybutów. Upewnij się, że ustawiony identyfikator komórki jest taki sam jak

static NSString *CellIdentifier = @"YourCellIdenifier";
 2
Author: honkskillet,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-14 05:26:07

Miałem ten sam problem, miałem ten sam błąd i dla mnie to działało tak:

[self.tableView registerNib:[UINib nibWithNibName:CELL_NIB_HERE bundle: nil] forCellReuseIdentifier:CELL_IDENTIFIER_HERE];
Może przyda się komuś innemu.
 2
Author: CarmenA,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-24 11:22:00

Skonfigurowałem wszystko poprawnie w Storyboardzie i zrobiłem czystą kompilację, ale otrzymywałem błąd "muszę zarejestrować stalówkę lub klasę dla Identyfikatora lub podłączyć prototypową komórkę w storyboardzie "

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

Poprawiłem błąd, ale nadal jestem w rozsypce. Nie używam "niestandardowej komórki", tylko widok z osadzonym widokiem tableview. Zadeklarowałem viewcontroller jako delegat i datasource i upewniłem się, że identyfikator komórki pasuje do pliku. co tu się dzieje?

 2
Author: FrostyL,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-29 19:17:02

Praca z Swift 3.0:

override func viewDidLoad() {
super.viewDidLoad()

self.myList.register(UINib(nibName: "MyTableViewCell", bundle: nil), forCellReuseIdentifier: "Cell")
}



public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = myList.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath) as! MyTableViewCell

return cell
}
 2
Author: norbDEV,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-26 18:44:32

To może wydawać się głupie dla niektórych ludzi, ale mnie to dopadło. Otrzymywałem ten błąd i problemem dla mnie było to, że próbowałem używać komórek statycznych, ale potem dynamicznie dodawać więcej rzeczy. Jeśli wywołujesz tę metodę, twoje komórki muszą być dynamicznymi prototypami. Wybierz komórkę w storyboard i pod inspektorem atrybutów pierwsza rzecz mówi "zawartość" i powinieneś wybrać dynamiczne prototypy, a nie statyczne.

 1
Author: Chase Roberts,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-16 18:12:47

Tylko uzupełnienie odpowiedzi: Może kiedyś wszystko ustawisz poprawnie, ale możesz przypadkowo dodać w sobie inne Ui .xib, np. UIButton:Tutaj wpisz opis obrazka Po prostu usuń dodatkowy interfejs użytkownika, to działa.

 1
Author: DrustZ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-25 15:00:07

Upewnij się, że CellIdentifier == identyfikator komórki w storyboardzie, obie nazwy są takie same. Hope this works for u

 1
Author: Ankit garg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-17 09:49:01

W moim przypadku wypadek zdarzył się, gdy zadzwoniłem deselectRowAtIndexPath:

Linia była [tableView deselectRowAtIndexPath:indexPath animated:YES];

Zmieniając go na [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; naprawiłem mój PROBLEM!

Mam nadzieję, że to komuś pomoże]}
 0
Author: Offek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-02 22:34:29

W języku Swift ten problem można rozwiązać dodając następujący kod w swoim

ViewDidLoad

Metoda.

tableView.registerClass(UITableViewCell.classForKeyedArchiver(), forCellReuseIdentifier: "your_reuse_identifier")
 0
Author: arango_86,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-19 05:37:02