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

时间:2013-08-29 19:55:35

标签: iphone xcode

我对此非常陌生,请原谅我容易修复的错误

·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文件

2 个答案:

答案 0 :(得分:1)

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

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

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

您的本地变量正在隐藏您的实例变量,因为它们都被命名为banner。类似于以下代码隐藏外部变量的方式:

id var;
{
    id var;
}

您可以通过将参数重命名为aBanner

来避免这种情况

答案 1 :(得分:1)

你没有关闭你的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
}

我怀疑周围还有其他类似的错误。请一步一步地重复一遍。

缩进代码并保持整洁有助于避免这样的问题。 :)