我试图从 UIViewController.m 上声明的 UIButton 获取当前标题,将其存储在 NSString 中,然后将其传递给 UITableView 控制器以将其用作 NSFetchRequest 的参数。
MainMenuViewController.h
- (IBAction)salesMan:(UIButton *)sender;
@property (nonatomic,strong) NSString *bPerson;
MainMenuViewController.m
#import "MainMenuViewController.h"
#import "DisplayResultsViewController.h"
// more code here...
- (IBAction)salesMan:(UIButton *)sender {
self.bPerson = sender.currentTitle;
}
@end
DisplayResultsViewController.h
@property (nonatomic, strong) NSString *sPerson;
DisplayResultsViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
context = [appDelegate managedObjectContext];
MainMenuViewController *mainMenu = [[MainMenuViewController alloc]init];
self.sPerson = mainMenu.bPerson;
NSLog(@" %@", self.sPerson);
}
问题是它没有传递 NSLog 返回“null”的变量