从 Objective-C 中的另一个 class 访问一次变量

Access variable in once from another class in Objective-C

我有两个 classes 在一个变量中声明了字符串并尝试从另一个 class 访问。当我尝试从 subclass.

打印时,在它们之间启动了 getter setter 仍然得到空值

CustomerCarSelection.h

    #import <UIKit/UIKit.h>

    @interface CustomerCarSelection : UITableViewController <UITableViewDataSource, UITableViewDataSource>

    @property (strong, nonatomic) IBOutlet UITableView *carListTableView;
    - (IBAction)next:(id)sender;

    @property NSString *carSelectedForService;

    @end

customerCarSelection.m

    #import "CustomerCarSelection.h"
    #import <Parse/Parse.h>
    #import "carSelectCellTableViewCell.h"
    #import "ServiceResultView.h"
    @interface CustomerCarSelection ()

    @end

    @implementation CustomerCarSelection


    @synthesize carListTableView;
    @synthesize carSelectedForService;
    - (void)viewDidLoad {
        [super viewDidLoad];

        ServiceResultView *service = [[ServiceResultView alloc]init];
        service.pointer = self;
    }
    -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"cell tabbed");
        PFObject *temp = [cellDetails objectAtIndex:indexPath.row];

        carSelectedForService = temp.objectId;

        NSLog(@"%@", carSelectedForService);

    }

serviceResultView.h

    #import <UIKit/UIKit.h>
    #import "CustomerCarSelection.h"
    @interface ServiceResultView : UIViewController
    {
        CustomerCarSelection *pointer;
    }
    @property (nonatomic, retain) CustomerCarSelection *pointer;

    - (IBAction)confirm:(id)sender;

    @end

serviceResultView.m

    #import "ServiceResultView.h"
    #import "CustomerCarSelection.h"
    @interface ServiceResultView ()

    @end

    @implementation ServiceResultView
    @synthesize pointer;
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.




        NSString *carResult = pointer.carSelectedForService;
        NSLog(@"%@", carResult);

    }

我哪里出错了。当单元格被选中时,它会将对象 ID 分配给我尝试从另一个 class

访问该对象的字符串
CustomerCarSelection.h

#import <UIKit/UIKit.h>


@interface CustomerCarSelection : UITableViewController <UITableViewDataSource, UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UITableView *carListTableView;

- (IBAction)next:(id)sender;



@end


customerCarSelection.m

#import "CustomerCarSelection.h"
#import <Parse/Parse.h>
#import "carSelectCellTableViewCell.h"
#import "ServiceResultView.h"
@interface CustomerCarSelection ()

@end

@implementation CustomerCarSelection


@synthesize carListTableView;
@synthesize carSelectedForService;

- (void)viewDidLoad {
    [super viewDidLoad];

}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"cell tabbed");
    PFObject *temp = [cellDetails objectAtIndex:indexPath.row];
    serviceResultView *obj = [serviceResultView alloc] init];
    obj.carSelectedForService = temp.objectId;

    NSLog(@"%@", obj.carSelectedForService);

}


serviceResultView.h

#import <UIKit/UIKit.h>
#import "CustomerCarSelection.h"
@interface ServiceResultView : UIViewController
@property NSString *carSelectedForService;
- (IBAction)confirm:(id)sender;

@end

serviceResultView.m

#import "ServiceResultView.h"
#import "CustomerCarSelection.h"
@interface ServiceResultView ()

@end

@implementation ServiceResultView
@synthesize pointer;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.




    NSLog(@"%@", self.carSelectedForService);

}