我有两个类在一个变量中声明了字符串并尝试从另一个类访问。当我尝试从子类打印时,他们之间的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分配给字符串我尝试从另一个类
访问该对象答案 0 :(得分:0)
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);
}