我想从我在实现文件中创建的NSArray导入值,但它似乎没有正确导入,因为我在Xcode中收到Use of undeclared identifier
错误。
我假设这是因为实现中的属性是私有的,因此其他类无法访问它。我在我的实现文件中创建了topCategory1和topCategory2,所以我不确定如何将其公开访问。有什么想法吗?
SearchCategoryChooserViewController.m:
#import "SearchCategoryChooserViewController.h"
#import "SearchViewController.m"
@interface SearchCategoryChooserViewController ()
@end
@implementation SearchCategoryChooserViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *category1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
category1.frame = CGRectMake(10, 120, 300, 35);
[category1 setTitle: [NSString stringWithFormat:@"%@", topCategory1] forState:UIControlStateNormal];
[category1 addTarget:self action:@selector(myButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: category1];
UIButton *category2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
category2.frame = CGRectMake(10, 180, 300, 35);
[category2 setTitle: [NSString stringWithFormat:@"%@", topCategory2] forState:UIControlStateNormal];
[category2 addTarget:self action:@selector(myButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: category2];
// Do any additional setup after loading the view.
}
SearchViewController.m(我要从中导入的类):
#import "SearchViewController.h"
@interface SearchViewController ()
@property (weak, nonatomic) IBOutlet UITextField *itemSearch;
@property (weak, nonatomic) IBOutlet UIButton *nextButton;
@property (weak, nonatomic) NSString *topCategory1;
@property (weak, nonatomic) NSString *topCategory2;
@end
@implementation SearchViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.nextButtonOutlet addTarget:self action:@selector(nextButton:) forControlEvents:UIControlEventTouchUpInside];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)nextButton:(id)sender
{
if (self.itemSearch.text.length > 0) {
[PFCloud callFunctionInBackground:@"eBayCategorySearch"
withParameters:@{@"item": self.itemSearch.text}
block:^(NSDictionary *result, NSError *error) {
NSLog(@"'%@'", result);
NSArray *resultArray = [result objectForKey:@"results"];
NSDictionary *dictionary0 = [resultArray objectAtIndex:0];
NSNumber *numberOfTopCategories = [dictionary0 objectForKey:@"Number of top categories"];
NSDictionary *dictionary1 = [resultArray objectAtIndex:1];
NSNumber *topCategories = [dictionary1 objectForKey:@"Top categories"];
NSDictionary *dictionary2 = [resultArray objectAtIndex:2];
NSNumber *numberOfMatches = [dictionary2 objectForKey:@"Number of matches"];
NSDictionary *dictionary3 = [resultArray objectAtIndex:3];
NSNumber *userCategoriesThatMatchSearch = [dictionary3 objectForKey:@"User categories that match search"];
NSArray *topCategoriesArray = [dictionary1 objectForKey:@"Top categories"];
NSString *topCategory1 = [topCategoriesArray objectAtIndex:0];
NSString *topCategory2 = [topCategoriesArray objectAtIndex:1];
if (!error) {
if ([numberOfMatches intValue] == 1 ){
[self performSegueWithIdentifier:@"ShowMatchCenterSegue" sender:self];
}
else if ([numberOfMatches intValue] == 2){
[self performSegueWithIdentifier:@"ShowUserCategoryChooserSegue" sender:self];
}
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 1) {
[self performSegueWithIdentifier:@"ShowCriteriaSegue" sender:self];
}
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 2) {
[self performSegueWithIdentifier:@"ShowSearchCategoryChooserSegue" sender:self];
}
}
}];
}
}
#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([segue.identifier isEqualToString:@"ShowSearchCategoryChooserSegue"]){
// SearchCategoryChooserViewController *controller = (SearchCategoryChooserViewController *) segue.destinationViewController;
// controller.itemSearch.text = self.itemSearch.text;
// }
}
@end