0
我一直在試圖將iAD實現到我的一個視圖控制器中,並且在爲.h和.m文件編寫代碼之後....我得到了這個語義問題錯誤:關於如何解決這個「語義問題」錯誤的建議
@synthesize of 'weak' property is only allowed in ARC or GC mode
我專門讓旁邊的.m文件的@implementation此錯誤。任何關於如何解決這個問題的建議都非常感謝。
還有我想知道是否可以將此adbanner(一旦它的工作)從此viewcontroller複製並粘貼到其他視圖控制器而無需重新編碼?
這是.h文件內我的代碼的iAD
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface ViewController : UIViewController <ADBannerViewDelegate>
@property (weak, nonatomic) IBOutlet ADBannerView *banner;
@end
這是.m文件
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.banner.delegate = self;
}
- (void) viewDidLayoutSubviews {
if (self.banner.bannerLoaded) {
CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = self.banner.frame;
contentFrame.size.height -= self.banner.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
self.banner.frame = bannerFrame;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication: (BOOL)willLeave
{
NSLog(@"bannerViewActionShouldBegin");
return YES;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"bannerViewDidLoadAd");
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"didFailToReceiveAdWithError");
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
NSLog(@"bannerViewActionDidFinish");
}
@end
您是否嘗試啓用ARC? '弱'只能用於ARC(iOS上沒有垃圾回收) –
@Matthias Bauch是的,這聽起來很愚蠢,但我該怎麼做?並請解釋你的報價 – user2459150
在Xcode的Edit - > Refactor菜單中有一個「Convert to Objective-C ARC」菜單項。但是在做這件事之前,你應該教育自己關於ARC,這可能會導致你現有的代碼出現問題。如果你想堅持手動發佈模型,用'assign'替換'weak'。 –