我如何修复“预期表达”

时间:2013-08-29 19:33:32

标签: iphone ios

我是新手,所以任何帮助都将不胜感激。提前致谢

·H

IBOutlet UITextField *textField1;
IBOutlet UITextField *textField2;
IBOutlet UILabel *label1;
@end

的.m

-(IBAction)calculate {                           **This is the line with the problem**
int x = ([textField1.text floatValue]);
int c = x*([textField2.text floatValue]);
   [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

1 个答案:

答案 0 :(得分:1)

坦率地说,看起来你的实施中炸弹爆炸了。首先,您似乎在.m的开头缺少@implementation指令。然后,您可以在IBAction中调用[super viewDidLoad];,它应该位于缺少的viewDidLoad方法中。

此外,您从未在IBAction结束时添加右括号}

您的.h文件应如下所示:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UITextField *textField1;
    IBOutlet UITextField *textField2;
    IBOutlet UILabel *label1;
}
@end

你的.m应该是这样的:

#import "ViewController.h"

@implementation ViewController

- (IBAction)calculate {
    int x = ([textField1.text floatValue]);
    int c = x*([textField2.text floatValue]);
}

- (void)viewDidLoad
{
    [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