iOS 8情节提要:UIStoryboardShowSegueTemplate上的异常

iOS 8情节提要:UIStoryboardShowSegueTemplate上的异常,ios,objective-c,uistoryboard,uistoryboardsegue,Ios,Objective C,Uistoryboard,Uistoryboardsegue,我现在对故事板有问题。。。我不知道会发生什么,但每次我试图改变场景时,我都会遇到一个例外: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:-[UIStoryboardShowSegueTemplate视图]:发送到实例0x7b05eae0的选择器无法识别 我所做的只是在导航栏中添加一个条按钮项,按住Ctrl键并拖动到我想要定位的控制器,然后选择“显示”。知道发生了什么事吗 编辑: ToDoListTableViewController: #impo

我现在对故事板有问题。。。我不知道会发生什么,但每次我试图改变场景时,我都会遇到一个例外:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:-[UIStoryboardShowSegueTemplate视图]:发送到实例0x7b05eae0的选择器无法识别

我所做的只是在导航栏中添加一个条按钮项,按住Ctrl键并拖动到我想要定位的控制器,然后选择“显示”。知道发生了什么事吗

编辑:

ToDoListTableViewController:

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

@interface ToDoListTableViewController ()

@property NSMutableArray *toDoItems;

@end

@implementation ToDoListTableViewController


- (IBAction)unwindToList:(UIStoryboardSegue *)segue {
    // Retrieves view controller's data
    AddToDoItemViewController *source = [segue sourceViewController];

    // Retreives the to-do item created and adds it if not null
    ToDoItem *item = source.toDoItem;
    if (item != nil) {
        [self.toDoItems addObject:item];
        [self.tableView reloadData];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];

    // Add a property to the class : a Mutable array that will contains the toDoItems
    self.toDoItems = [[NSMutableArray alloc] init];

    // Load initial random data to the toDo array
    [self loadInitialData];
}

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

/**
 *  Loads initial data, random dumb one right now
 */
- (void)loadInitialData {
    ToDoItem *item1 = [[ToDoItem alloc] init];
    item1.itemName = @"First item";
    [self.toDoItems addObject:item1];

    ToDoItem *item2 = [[ToDoItem alloc] init];
    item2.itemName = @"Second item";
    [self.toDoItems addObject:item2];

    ToDoItem *item3 = [[ToDoItem alloc] init];
    item3.itemName = @"Third item";
    [self.toDoItems addObject:item3];
}

#pragma mark - Table view data source

/**
 *  Sets the number of sections in table view
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

/**
 *  Sets the number of rows in the table view
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section (e.g number of items in array)
    return [self.toDoItems count];
}

/**
 *  Define the behavior of each cell in the table view.
 *  This is here that all graphical stuff must be done.
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListPrototypeCell" forIndexPath:indexPath];

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

    // Set the checkmark if the task had been completed or remove it
    if (toDoItem.completed) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

#pragma mark - Table view delegate

/**
 *  Delegate method : detects user's input on a table cell and acts accordingly
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Do not select the cell tapped
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    // Detects which cell has been tapped
    ToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];

    // Toggle completion of task
    tappedItem.completed = !tappedItem.completed;

    // Reload cell into table view
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

@end
#import "AddToDoItemViewController.h"

@interface AddToDoItemViewController ()

@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;
- (IBAction)customEvent:(id)sender;

@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

/**
 *  Launched before changing view
 *  In this case, the "Save" button has been linked to the back segue
 */
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Do not do anything and leave the function if the button tapped is not the Save button
    if (sender != self.saveButton) return;

    // If the field is not empty, we create a new to-do item and sets its text.
    // We also set its completion to "NO" (we don't want to have auto-completed tasks on creation)
    if (self.textField.text.length > 0) {
        self.toDoItem = [[ToDoItem alloc] init];
        self.toDoItem.itemName = self.textField.text;
        self.toDoItem.completed = NO;
    }
}

@end
AddToDoItemViewController:

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

@interface ToDoListTableViewController ()

@property NSMutableArray *toDoItems;

@end

@implementation ToDoListTableViewController


- (IBAction)unwindToList:(UIStoryboardSegue *)segue {
    // Retrieves view controller's data
    AddToDoItemViewController *source = [segue sourceViewController];

    // Retreives the to-do item created and adds it if not null
    ToDoItem *item = source.toDoItem;
    if (item != nil) {
        [self.toDoItems addObject:item];
        [self.tableView reloadData];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];

    // Add a property to the class : a Mutable array that will contains the toDoItems
    self.toDoItems = [[NSMutableArray alloc] init];

    // Load initial random data to the toDo array
    [self loadInitialData];
}

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

/**
 *  Loads initial data, random dumb one right now
 */
- (void)loadInitialData {
    ToDoItem *item1 = [[ToDoItem alloc] init];
    item1.itemName = @"First item";
    [self.toDoItems addObject:item1];

    ToDoItem *item2 = [[ToDoItem alloc] init];
    item2.itemName = @"Second item";
    [self.toDoItems addObject:item2];

    ToDoItem *item3 = [[ToDoItem alloc] init];
    item3.itemName = @"Third item";
    [self.toDoItems addObject:item3];
}

#pragma mark - Table view data source

/**
 *  Sets the number of sections in table view
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

/**
 *  Sets the number of rows in the table view
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section (e.g number of items in array)
    return [self.toDoItems count];
}

/**
 *  Define the behavior of each cell in the table view.
 *  This is here that all graphical stuff must be done.
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListPrototypeCell" forIndexPath:indexPath];

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

    // Set the checkmark if the task had been completed or remove it
    if (toDoItem.completed) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

#pragma mark - Table view delegate

/**
 *  Delegate method : detects user's input on a table cell and acts accordingly
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Do not select the cell tapped
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    // Detects which cell has been tapped
    ToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];

    // Toggle completion of task
    tappedItem.completed = !tappedItem.completed;

    // Reload cell into table view
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

@end
#import "AddToDoItemViewController.h"

@interface AddToDoItemViewController ()

@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;
- (IBAction)customEvent:(id)sender;

@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

/**
 *  Launched before changing view
 *  In this case, the "Save" button has been linked to the back segue
 */
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Do not do anything and leave the function if the button tapped is not the Save button
    if (sender != self.saveButton) return;

    // If the field is not empty, we create a new to-do item and sets its text.
    // We also set its completion to "NO" (we don't want to have auto-completed tasks on creation)
    if (self.textField.text.length > 0) {
        self.toDoItem = [[ToDoItem alloc] init];
        self.toDoItem.itemName = self.textField.text;
        self.toDoItem.completed = NO;
    }
}

@end

您需要显示更多的代码。是否在视图控制器中添加了prepareForSegue函数?错误似乎暗示正在从segue对象请求“view”属性。你在代码中的任何地方都使用过segue吗?我已经编辑了我的问题以放置一些代码,但是我没有提到这个特殊的segue。当我在表视图控制器中时,当我想添加一个待办事项(单击“+”按钮)时,我遇到了问题。当展开到“待办事项”或显示“AddItem”时,是否会发生崩溃?@joakim:当显示“AddItem”时,是否有异常发生时调试器的回溯?如果没有,请尝试添加异常断点,然后重新运行程序。将错误调用的回溯发布到-[UIStoryboardShowSegueTemplate view]将有所帮助。