Ios iPhone授权错误

Ios iPhone授权错误,ios,objective-c,delegates,getter-setter,delegation,Ios,Objective C,Delegates,Getter Setter,Delegation,我有两种观点。firstView和secondView。firstView需要来自secondView的favorites数组,因此我尝试调用协议中定义的getfavorites方法。然而,它返回null,这对我来说似乎很奇怪,因为一切都有意义 这是firstViewController.h: #import <UIKit/UIKit.h> #import "Drink.h" @protocol firstViewControllerDelegate; @interface Fi

我有两种观点。
firstView
secondView
firstView
需要来自
secondView
的favorites数组,因此我尝试调用协议中定义的
getfavorites
方法。然而,它返回null,这对我来说似乎很奇怪,因为一切都有意义

这是
firstViewController.h

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

@protocol firstViewControllerDelegate;

@interface FirstViewController : UIViewController
{
    id <firstViewControllerDelegate> delegate;
    NSMutableArray *labels;

    UIButton *button1;
    UIButton *button2;
    UIButton *button3;
    UIButton *button4;
}

- (IBAction) buttonClick: (id) sender;

@property (nonatomic, assign) id <firstViewControllerDelegate> delegate;
@property (nonatomic, retain) IBOutlet UIButton *button1;
@property (nonatomic, retain) IBOutlet UIButton *button2;
@property (nonatomic, retain) IBOutlet UIButton *button3;
@property (nonatomic, retain) IBOutlet UIButton *button4;

@end

@protocol firstViewControllerDelegate
- (NSMutableArray *) getFavourites;
- (void) setFavourites: NSMutableArray;
@end
SecondViewController.h

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

@interface SecondViewController: UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, firstViewControllerDelegate>
{
        NSMutableArray *favourites;
        NSMutableArray *drinks;
}

@property (nonatomic, retain) NSMutableArray *drinks;
@property (nonatomic, retain, getter = getFavourites) NSMutableArray *favourites;

- (void) addDrink: (NSString *) name;

@end
#导入
#导入“FirstViewController.h”
@界面SecondViewController:UIViewController
{
NSMutableArray*收藏夹;
NSMutableArray*饮料;
}
@属性(非原子,保留)NSMutableArray*饮料;
@属性(非原子、保留、getter=getFavorites)NSMutableArray*Favorites;
-(void)addDrink:(NSString*)名称;
@结束

有人知道这为什么不起作用吗?

您确定要设置FirstViewController的委托属性吗?i、 e:

FirstViewController *firstController = // Instantiate the controller;
firstController.delegate = secondController;
[self.navigationController pushViewController:firstController animated:YES];

secondController
在实例化之前应该存在,否则您将设置一个
nil

是否检查在调用getFavorites时是否分配了代理?您的意思是什么?需要将其分配给什么以及如何分配?将委托属性替换为
@property(非原子,保留)IBOutlet SecondViewController*delegate
,转到xib,放置视图控制器图标,将其设置为SecondController,并将其链接到属性。另一种方法是在viewDidLoad中实例化控制器。我认为您不太了解委托和控制器的概念,但这不会阻止您实现这一点。我添加了您提到的属性。我不太确定如何使用第一种方法,所以我使用了第二种方法。因此,您可以使用UIViewController*secondViewController=[[UIViewController alloc]init]在viewDidLoad方法中实例化它;那么您将如何分配该代表?
FirstViewController *firstController = // Instantiate the controller;
firstController.delegate = secondController;
[self.navigationController pushViewController:firstController animated:YES];