我正在编写有关创建应用的教程。我跟着一起,把所有内容都写成了教程。然而,当我点击构建时,我得到了一些错误。 下面是我在实现文件中的方法代码片段。我收到一个错误....(scrollTheView'未申报)...我还有另一个错误堆叠(预期';'之前':'令牌).....
在这个方法下面,我将包含我的整个Header文件,我已经声明了方法“scrollTheView”,所以我不明白我哪里出错了。该教程使用的是SDK iPhone OS 2.2.1,但我使用的是SDK iphone 4.3,这可能是导致此问题的真正原因吗?我编辑了帖子以包含整个实现文件。在代码结束时,我还会在输入结束时收到错误的“预期声明或声明”,并在实施环境中收到另一个“@end”缺失声明,感谢所有观看并试图帮助我的人。 谢谢scott帮我解决了那个缺失的括号..现在我有一个通知,即使它编译也会弹出..“UIKeyboardBoundsUserInfoKey已被弃用通知”任何人都知道这意味着什么?因为它编译,我应该担心吗?它出现在'keyboardVillShow'方法下的“NSValue * aValue .....”行中
#import "ReturnToMeViewController.h"
#import "ReturnToMeAppDelegate.h"
@implementation ReturnToMeViewController
@synthesize textField;
@synthesize label;
@synthesize callNumber;
-(void)viewDidLoad {
textField.clearButtonMode =
UITextFieldViewModeWhileEditing;
[super viewDidLoad];
}
-(void) viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
[super viewWillAppear:animated];
}
-(void) viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification object:nil];
[super viewWillDisappear:animated];
}
-(void)keyboardWillShow: (NSNotification *)notif {
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue] .size;
float bottomPoint = (textField.frame.origin.y+textField.frame.size.height+10);
scrollAmount = keyboardSize.height - (self.view.frame.size.height- bottomPoint);
if (scrollAmount >0) {
moveViewUp =YES;
[self scrollTheView:YES];
}
else {
moveViewUp =NO;
}
-**(void) scrollTheView:(BOOL) movedUp {**
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
if (movedUp) {
rect.origin.y -= scrollAmount;
}
else {
rect.origin.y += scrollAmount;
}
self.view.frame = rect;
[UIView commitAnimations];
}
-(void)touchesBegan: (NSSet *) touches withEvent: (UIEvent *)event {
if ( textField.editing) {
[textField resignFirstResponder];
[self updateCallNumber];
if (moveViewUp) [self scrollTheView:NO];
}
[super touchesBegan:touches withEvent:event];
}
-(void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
-(void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(void)dealloc {
[textField release];
[label release];
[callNumber release];
[super dealloc];
}
-(BOOL)textFieldShouldReturn: (UITextField *)theTextField {
[theTextField resignFirstResponder];
if (moveViewUp) [self scrollTheView:NO];
[self updateCallNumber];
return YES;
}
-(void)updateCallNumber {
self.callNumber = textField.text;
label.text = self.callNumber;
}
@end
###ReturnToMeViewController.m
#import < UIKit/UIKit.h >
@interface ReturnToMeViewController : UIViewController
< UITextFieldDelegate > {
IBOutlet UITextField *textField;
IBOutlet UILabel *label;
BOOL moveViewUp;
CGFloat scrollAmount;
NSString *callNumber;
}
@property (nonatomic, retain) UITextField *textField;
@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) NSString *callNumber;
- (void)scrollTheView:(BOOL) movedUp;
- (void)updateCallNumber;
**@end**
答案 0 :(得分:0)
听起来你错过了一个紧密的括号“}”或分号“;”在您的scrollTheView函数之前的某个地方。
答案 1 :(得分:0)
在声明scrollTheView之前可能会出现错误,这意味着它无法检测scrollTheView。在这里查看或发布更多代码。
答案 2 :(得分:0)
您在keyboardWillShow:(NSNotification *)notif
方法的末尾错过了一个结束括号。
if (scrollAmount >0) {
moveViewUp =YES;
[self scrollTheView:YES];
}
else {
moveViewUp =NO;
} // This is where the missing bracket should be
}
需要有两个右括号 - 一个用于if
语句,一个用于方法 - 但只有一个。