Vielleicht kann mir jemand helfen. Ich möchte eine neue Tabellenansicht Zeile zu einem tableView
hinzufügen. Wenn Sie die Plus-Taste in der oberen rechten Ecke drücken, erscheint eine Warnung und Sie können Text eingeben, und dieser Text wird zur Tabelle hinzugefügt.Hinzufügen von TableView-Zeilen mit AlertAction
Wenn ich die Plus-Taste am Drücken ich immer erhalte eine Fehlermeldung
(SIGABRT: 'NSInvalidArgumentException', Grund: '* - [__ NSArrayM insert: atIndex:]: Objekt kann nicht Null sein' * Erstwurf Anrufstapel :)
Ich verstehe es nicht.
@property NSMutableArray *objects;
@property NSString *shopping;
- (void)insertNewObject:(id)sender {
if (!self.objects) {
self.objects = [[NSMutableArray alloc] init];
}
//call an alert Action
UIAlertController *textEntry = [UIAlertController alertControllerWithTitle:@"new Item" message:@"" preferredStyle:UIAlertControllerStyleAlert];
[textEntry addTextFieldWithConfigurationHandler:^(UITextField *textField){
textField.placeholder = NSLocalizedString (@"zb. pickle", @"cde");
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
UITextField *enteredText = textEntry.textFields.firstObject;
_shopping = enteredText.text;
}];
[textEingabe addAction:okAction];
[self presentViewController:textEingabe animated:YES completion:nil];
[_objects insertObject:_shopping atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//Not quite sure if this is the right code
cell.textLabel.text = [_objects objectAtIndex:[indexPath row]];
return cell;
Diese auf die Frage keine vollständige Antwort. Bitte erklären Sie, was das Problem war und wie Sie es behoben haben, anstatt Arbeitscode –
Oh verdammt, ich bin dumm. Danke vielmals. Es hat funktioniert – podoi17
@ podoi17 Willkommen bro :-) –