/ / ToDoList-Tutorial für XCode No Getter Methode zum Lesen aus der Eigenschaft OBJ C - ios, Objective-c

ToDoList-Tutorial für XCode No Getter Methode zum Lesen aus der Eigenschaft OBJ C - ios, Objective-c

Ich habe das XCode-App-Entwicklungs-Tutorial jetzt einige Male durchgearbeitet und bin immer wieder auf den gleichen Fehler gestoßen.

source.ToDoItem gibt den Fehler "Keine Getter-Methode zum Lesen aus der Eigenschaft" aus.

Irgendwelche Ideen, wie man das löst? Ich kann anscheinend keine korrekte Getter-Methode schreiben und ich kann im Entwicklungs-Tutorial kein Beispiel finden, von dem ich ausgehen kann.

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

}

ToDoItem.h

#import <Foundation/Foundation.h>

@interface ToDoItem : NSObject

@property NSString *itemName;
@property BOOL completed;
@property (readonly) NSDate *creationDate;

@end

ToDoItem.m

#import "ToDoItem.h"

@implementation ToDoItem

@end

ToDoListTableViewController

#import "ToDoListTableViewController.h"

#import "AddToDoItemViewController.h"
#import "ToDoItem.h"

@interface ToDoListTableViewController ()

@property NSMutableArray *toDoItems;

@end

@implementation ToDoListTableViewController

- (void)loadInitialData {
ToDoItem *item1 = [[ToDoItem alloc] init];
item1.itemName = @"things";
[self.toDoItems addObject:item1];
ToDoItem *item2 = [[ToDoItem alloc] init];
item2.itemName = @"Things to do with things";
[self.toDoItems addObject:item2];
ToDoItem *item3 = [[ToDoItem alloc] init];
item3.itemName = @"Write Ethics Paper";
[self.toDoItems addObject:item3];

}

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

}

- (void)viewDidLoad {
[super viewDidLoad];

self.toDoItems = [[NSMutableArray alloc] init];
[self loadInitialData];

// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [self.toDoItems count];
}


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

ToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
// Configure the cell...

if (toDoItem.completed) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}

return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
ToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];
tappedItem.completed = !tappedItem.completed;
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
@end

und ToDoListTableViewController.h

#import <UIKit/UIKit.h>
#import "ToDoItem.h"
#import "AddToDoItemViewController.h"

@interface ToDoListTableViewController : UITableViewController
- (IBAction)unwindToList:(UIStoryboardSegue *)segue;

@end

AddToDoItemViewController.m

#import "AddToDoItemViewController.h"
#import "ToDoItem.h"



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

@property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;


@end

@implementation AddToDoItemViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if (sender != self.saveButton) return;
if (self.textField.text.length > 0) {
}
self.toDoItem = [[ToDoItem alloc] init];
self.toDoItem.itemName = self.textField.text;
self.toDoItem.completed = NO;
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}



@end

AddToDoItemViewController.h

#import <UIKit/UIKit.h>
#import "ToDoItem.h"

@interface AddToDoItemViewController : UIViewController


@property ToDoItem *toDoItem;
@property NSString *itemName;
@property BOOL completed;
@property (readonly) NSDate *creationDate;

@end

Antworten:

0 für die Antwort № 1

Im AddToDoItemViewController du hast

@property ToDoItem *toDoItem;

aber im Code verwenden Sie es als:

ToDoItem *item = source.ToDoItem;

wo soll es sein:

ToDoItem *item = source.toDoItem;

Beachten Sie die Namenskonvention. Der Klassenname beginnt mit einem Großbuchstaben und der Eigenschaftsname mit einem Kleinbuchstaben.


0 für die Antwort № 2

Versuchen Sie, diese beiden Zeilen zu ändern:

@property NSString *itemName;
@property BOOL completed;

Dafür:

@property (nonatomic, strong) NSString *itemName;
@property (nonatomic, readwrite) BOOL completed;