问题:实现不完整,'banner'的本地声明隐藏了实例变量,预期的表达式,缺少@end



我对此很陌生,所以请原谅容易修复的错误

.h

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface withadViewController : UIViewController <ADBannerViewDelegate>{
ADBannerView *banner;
BOOL bannerIsVisible;
IBOutlet UITextField *textField1;
IBOutlet UITextField *textField2;
IBOutlet UILabel *label1;
}
@property (nonatomic, assign)BOOL bannerIsVisible;
@property (nonatomic, retain)IBOutlet ADBannerView *banner;
-(IBAction)calculate;
-(IBAction)clear;
@end

.m(其中所有问题都是由于未知原因引起的)

#import "withadViewController.h"
@interface withadViewController ()                  HERE IT SAYS INCOMPLETE IMPLEMENTATION
@end
@implementation withadViewController
@synthesize banner;
@synthesize bannerIsVisible;
-(void) bannerViewDidLoadAd:(ADBannerView *)banner {
if (!self.bannerIsVisible) {
    [UIView beginAnimations:@"animatedAdBannerOn" context:NULL];
    banner.frame = CGRectOffset(banner.frame, 0.0, 50.0); HERE SAYS LOCAL DECLARATION OF BANNER HIDES INSTANCE VARIABLE
    [UIView commitAnimations];
    self.bannerIsVisible = YES;
    }
}
-(void)bannerView:(ADBannerView *)aBanner didFailToReceiveAdWithError:(NSError *)error {
if (!self.bannerIsVisible) {
    [UIView beginAnimations:@"animatedAdBannerOff" context:NULL];
    banner.frame = CGRectOffset(banner.frame, 0.0, -320.0);
    [UIView commitAnimations];
    self.bannerIsVisible = NO;
}
 -(IBAction)calculate {                           HERE IT SAYS EXPECTED EXPRESSION
int x = ([textField1.text floatValue]);
int c = x*([textField2.text floatValue]);
label1.text = [[NSString alloc]initWithFormat:@"%2d", c];
}
-(IBAction)clear {
textField1.text = @"";
textField2.text = @"";
label1.text = @"";{
}
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}  
@end                                                             HERE IT SAYS MISSING @END

这是

的所有.h和.m文件

您永远不会关闭您的方法:

-(void)bannerView:(ADBannerView *)aBanner didFailToReceiveAdWithError:(NSError *)error

这导致编译器看不到您已经实现的方法(不完整的实现),不理解@end并期望表达式。

您的局部变量正在隐藏您的实例变量,因为这两个变量都命名为banner。类似于以下代码隐藏外部变量的方式:

id var;
{
    id var;
}

您可以通过将参数重命名为类似aBanner的名称来避免这种情况。

您没有关闭if语句:

- (void)bannerView:(ADBannerView *)aBanner didFailToReceiveAdWithError:(NSError *)error {
    if (!self.bannerIsVisible) {
        [UIView beginAnimations:@"animatedAdBannerOff" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0.0, -320.0);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    } // <-- HERE
}

我怀疑还有其他类似的错误。再一遍,一步一步。

缩进代码并保持其整洁对避免此类问题有很大帮助。:)

最新更新