3

我遇到了一个似乎相当普遍的问题,但我无法具体弄清楚我的代码有什么问题。

我已经搜索了 stackoverflow 并阅读了至少十几篇与我相似的帖子,但我无法弄清楚我的个人问题。

基本上,我试图将 NSMutableDictionary 从模式视图传递到主视图。这是代码:

QuoteMasterViewController.h:

    @class QuoteModalViewController;
    @interface QuoteMasterViewController : UITableViewController
    @end

QuoteMasterViewController.m:

#import "QuoteMasterViewController.h"
#import "QuoteModalViewController.h"
#import "QuoteDetailViewController.h"

@interface QuoteMasterViewController () {
    NSMutableArray *_objects;
    }
@end

@implementation QuoteMasterViewController

//after the ViewDidLoad method...

-(void)addQuotationWithDictionary: (NSMutableDictionary *)myDictionary {

     [self insertNewObject:myDictionary];
     [self dismissModalViewControllerAnimated:YES];
 }

QuoteModalViewController.h:

 #import <UIKit/UIKit.h>

 @class QuoteMasterViewController;

 @interface QuoteModalViewController : UIViewController <UITextFieldDelegate>

 @property (nonatomic, weak) QuoteMasterViewController *masterView;
 @property (strong, nonatomic) IBOutlet UITextField *sourceQuoted;
 @property (strong, nonatomic) IBOutlet UITextField *quoteQuoted;
 - (IBAction)saveButtonPressed:(id)sender;
 - (IBAction)cancelButtonPressed:(id)sender;

 @end

QuoteModalViewController.m:

#import "QuoteModalViewController.h"
#import "QuoteMasterViewController.h"

@interface QuoteModalViewController ()

@end

@implementation QuoteModalViewController

@synthesize sourceQuoted;
@synthesize quoteQuoted;
@synthesize masterView;


//After ViewDidLoad
- (IBAction)saveButtonPressed:(id)sender {
    if (![sourceQuoted.text isEqualToString:@""] && ![quoteQuoted.text isEqualToString:@""]) {
        NSString *sourceString = sourceQuoted.text;
        NSString *quoteString = quoteQuoted.text;
        NSMutableDictionary *quotesDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: sourceString, @"Source", quoteString, @"Quote", nil];
        [masterView addQuotationWithDictionary:quotesDict]; //Error occurs here
        NSLog(@"%@", quotesDict);
    }
}

提前感谢您的任何帮助!

4

1 回答 1

7

您没有在头文件中声明您的方法。添加

-(void)addQuotationWithDictionary: (NSMutableDictionary *)myDictionary;

@interface QuoteMasterViewController到和之间的 QuoteMasterViewController.h 文件@end

于 2012-10-29T23:55:38.427 回答