0

我有一个带有 Add BarButton 的 UI 工具栏。我希望这会触发从属 viewController 中的操作。我被困住了。

工具栏设置如下:

TopViewController.h

IBOutlet UIToolbar* toolbar;
@property (retain, nonatomic) IBOutlet UIToolbar *homeButton;
@property (retain, nonatomic) IBOutlet UIToolbar *addButton;

- (IBAction)homePlease:(id)sender;
- (IBAction)addStuff:(id)sender;

TopViewController.m

@class ItemViewController;
#import "ItemViewController.h"

- (IBAction)homePlease:(id)sender {
    //NSLog(@"%s", __FUNCTION__);
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)addStuff:(id)sender {
    NSLog(@"%s", __FUNCTION__);
    [self.itemViewController insertNewObject:self]; <-----
}

项目视图控制器:

- (void)insertNewObject:(id)sender {
    //NSLog(@"%s", __FUNCTION__);

    AddItemViewController *addItem = [[AddItemViewController alloc] initWithNibName:@"AddItem-iPad" bundle:nil];


    // Create a new managed object context for the new item - set its persistent store coordinator
    // to the same as that from the fetched results controller's context.

    NSManagedObjectContext .......

    [self.addContext setPersistentStoreCoordinator:[[self.fetchedResultsController managedObjectContext] persistentStoreCoordinator]];

    addItem.item = (DDItem *)[NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:context];

    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:addItem];
    nc.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:nc animated:YES completion:nil];

}

主页按钮工作正常。

addButton 触发(我看到了日志)。但没有其他事情发生。添加按钮连接到 IBAction。

任何建议都将受到欢迎

4

1 回答 1

0

看来这个答案是正确的。您必须在其呈现视图控制器中设置按钮。我希望这对其他人有帮助。

于 2013-02-26T15:39:00.360 回答