多分誰かが私を助けることができます。 tableView
に新しいテーブルビュー行を追加したいと思います。右上隅のプラスボタンを押すと警告がポップアップし、テキストを入力するとこのテキストがテーブルに追加されます。理由は、 'NSInvalidArgumentException':私はプラスボタンを押していた場合AlertAction付きTableView行を追加
私は常にエラーに
(SIGABRTを取得しています '* - [__ NSArrayM は、insertObject:atIndexは:]:オブジェクトがnilすることはできません' *まずスローコールスタック:)
私はそれを得るいけません。
@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;
これは質問に対する完全な答えではありません。問題の内容と、作業コードを掲示するのではなく修正した方法を説明してください。 –
ああ私はばかです。どうもありがとう。それは働いた – podoi17
@ podoi17ようこそbro :-) –