1

I am new to iOS XCode and am attempting to complete the initial example. Everything works as expected and in debugging with breakpoints I cannot seem to set a value from the Add To-Do Item to show up in Self.textField, so the program just skips each of these steps and I am back to the initial list. UPDATE: It definitely does not seem to pass this line of code,

if (sender != self.doneButton) return;

thus all the other code does not execute either. Is it something to do with the configuration of the Text Field in the story board? - Thanks!

In AddToDoItemViewController.m the value in the text field does not seem to come across and get stored in this code.

#import "AddToDoItemViewController.h"

@interface AddToDoItemViewController ()

@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UITextField *doneButton;

@end

@implementation AddToDoItemViewController

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if (sender != self.doneButton) return;
    if (self.textField.text.length > 0) {
        self.toDoItem = [[ToDoItem alloc] init];
        self.toDoItem.itemName = self.textField.text;
        self.toDoItem.completed = NO;
    }
}

In ToDoListTableViewController.m, the action just sees that item is NILL so it is done...

- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
    AddToDoItemViewController *source = [segue sourceViewController];
    ToDoItem *item = source.toDoItem;
    if (item !=nil) {
        [self.toDoItems addObject:item];
        [self.tableView reloadData];
    }
}

It's driving me crazy as I have everything else working fine and am learning how nice the debugger is, but I just can't see where the problem is. Do you know if you can download the final code sample somewhere?

Thanks for any help here. It's July 4th and I won't be sleeping for quite a while... :}

  • It is kind of strange to name a text field `doneButton`. I assume this should be a button. Are you sure that the segue is correctly set in the storyboard? – dasdom Jul 05 '14 at 04:33
  • No I am not sure. How do I check? I am at the last section in this document. Thanks for trying to help. I think others have gotten this to work. I may have to start over to ensure that final DONE button will add New Items to the Mutable Array. https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/ThirdTutorial.html#//apple_ref/doc/uid/TP40011343-CH10-SW1 – Kalamazoo13 Jul 05 '14 at 04:44
  • Dasdom....you got me thinking and I dragged the DONE button to the AddToViewItemController and that is a UIBarButton and I replaced that one with what was in the Apple documentation and now it works! Thanks!! – Kalamazoo13 Jul 05 '14 at 05:00
  • Wait a minute, my bag, the Apple documentation is right and I am stupid...Time for some sleep. Thanks again! – Kalamazoo13 Jul 05 '14 at 05:09

1 Answers1

0

I have checked the document. You did something wrong. In the example the doneButton is a UIBarButtonItem. enter image description here

Did you also do this:

To create the unwind segue, link the Cancel and Done buttons to the unwindToList: action through the Exit icon in the dock of the source view controller, XYZAddToDoItemViewController.

dasdom
  • 13,975
  • 2
  • 47
  • 58
  • dasdom, you are the man! Yes, I did the 2 unwind segue but the trick was as you stated "the doneButton needed an outlet to the actual UIBarButtonItem NOT the same textField"... The Apple started guide is wrong and that can be very frustrating to a new person... :} I should try to alert them to the error and maybe post an errata here online somewhere. Thanks so much and Happy 4th! PC – Kalamazoo13 Jul 05 '14 at 05:04
  • Wait a minute, my bag, the Apple documentation is right and I am stupid...Time for some sleep. I have been trying to get this to work on and off over the past week...just needed to read straight..Thanks again! – Kalamazoo13 Jul 05 '14 at 05:11
  • Sleep well, now that it's fixed. :) – dasdom Jul 05 '14 at 05:22