실제로 Objective-C의 상속이 어떻게 작동하는지 알아 내려고합니다. 내 문제는, 그건 내 obj. allways "null"을 반환합니다.iOS - 상속은 어떻게 작동합니까?
여기 내 코드입니다.
편집 : 나머지 코드가 추가되었습니다.
// ReportViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "IAPHelper.h"
@class Report, Category, GADBannerView;
@interface ReportViewController : UIViewController <UIWebViewDelegate,
NSFetchedResultsControllerDelegate> {NSString* _werbung;}
@property (nonatomic, strong) GADBannerView *bannerView;
@property (nonatomic, retain) NSString* werbung;
- (id)initWithReport:(Report *)report category:(Category *)category ;
@end
// ReportViewController.m
#import "ReportViewController.h"
#import "IAPHelper.h"
@interface ReportViewController()
- (void)loadReport;
- (void)setupFetchRequest;
- (void)resizeNavigationContentViewToHeight:(CGFloat)height;
- (NSString*) werbung;
- (void)setWerbung:(NSString *)newwerbung;
@end
@implementation ReportViewController
@synthesize werbung = _werbung;
-(NSString*) werbung {
return _werbung;
}
- (void)setWerbung:(NSString *)newwerbung {
_werbung= newwerbung;
}
//Werbung ausblenden
NSLog(@"Check for bought products");
if ([_werbung isEqual: @"gekauft"]) {
self.bannerView.hidden = TRUE;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
self.edgesForExtendedLayout=UIRectEdgeNone;
self.navigationController.navigationBar.translucent = NO;
}
//ADMob
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) {
_bannerView = [[GADBannerView alloc] initWithFrame: CGRectMake(20.0,850.0,728,90)];}
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) {
_bannerView = [[GADBannerView alloc] initWithFrame: CGRectMake(-10,615.0,728,90)];}
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) {
_bannerView = [[GADBannerView alloc] initWithFrame: CGRectMake(-10,615.0,728,90)];}
}
else
_bannerView = [[GADBannerView alloc] initWithFrame: CGRectMake(0,410,320,50)];
//initWithAdSize:kGADAdSizeBanner];
//initwithframe:CGRectMake(0.0,0.0,320,50)];
self.bannerView.adUnitID = @„xxxxxxxxxxxxxxxxx“;
self.bannerView.rootViewController = self;
GADRequest *request = [GADRequest request];
// Enable test ads on simulators.
[self.view addSubview:(_bannerView)];
request.testDevices = @[ GAD_SIMULATOR_ID, @„xxxxxxxxxxxxxxxxxxxxxxx“ ];
[self.bannerView loadRequest:request];
//Werbung ausblenden
NSLog(@"Check for bought products");
if ([_werbung isEqual: @"gekauft"]) {
self.bannerView.hidden = TRUE;
}
NSLog(@"%@",_werbung);
NSLog(@"%@",self.werbung);
}
// IAPHelper.m
#import "IAPHelper.h"
#import <StoreKit/StoreKit.h>
#import "ReportViewController.h"
@interface IAPHelper() <SKProductsRequestDelegate, SKPaymentTransactionObserver>
@end
@implementation IAPHelper
- (id)initWithProductIdentifiers:(NSSet *)productIdentifiers
{
//self = [super init];
if ((self = [super init])) {
// Store product identifiers
_productIdentifiers = productIdentifiers;
// Check for previously purchased products
_purchasedProductIdentifiers = [NSMutableSet set];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
for (NSString * productIdentifier in _productIdentifiers) {
BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
if (productPurchased) {
[_purchasedProductIdentifiers addObject:productIdentifier];
NSLog(@"Previously purchased: %@", productIdentifier);
if ([productIdentifier isEqual:@"XXXXXXXXXXXXXXXXXXXXXXXXXX"]) {
ReportViewController *rvc = [[ReportViewController alloc] init];
rvc.werbung = @"gekauft";
NSLog(@"werbung gekauft!");
NSLog(@"%@", rvc.werbung); <- log's @"gekauft";
} else {
NSLog(@"Not purchased: %@", productIdentifier);
}
}
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}}
return self;
}
제 질문은 : 내가 뭘 잘못 했습니까? 어쩌면 너는 나를 위해 좋은 지침서를 가지고 있을까?
편집 : 당신이 맞았습니다. 상속에 관한 것이 아닙니다. 내 솔루션 UserDefaults 함께 작동합니다.
어떤 개체가 'null'인지 알 수 있습니까? – Hemang
NSLog (@ "% @", _werbung); <- 이것은 "null"입니다. NSLog (@ "% @", self.werbung); <-이 또한 "null"입니다 // 코드 btw에 표시되었습니다. –
그래서 _walbung을 nil이 아닌 곳에 설정하는 코드 행은 어디에 있습니까? – gnasher729