2011-06-30 52 views
0

我正在通过创建应用程序的教程。我一直跟着,并且一切都写得像教程一样。但是,当我点击构建时,我收到了一些错误。 下面是我在实现文件中的一个方法的代码片段。我得到一个错误....(scrollTheView'未声明)...我还有另一个错误堆积它是(预期';'之前':'代币).....错误“scrollTheView”未声明的问题

在此之下方法我将包括我的整个头文件,我已经声明了方法“scrollTheView”,所以我不明白我出错的地方。本教程使用SDK iPhone OS 2.2.1,但是我使用的是SDK 4.3,这可能是导致此问题的真正原因吗?我已经编辑过这个帖子来包含整个实现文件。在代码的最后,我还得到了一个错误,“在输入结束时出现预期的声明或声明”,另一个错误是在实现上下文中缺少'@end'谢谢所有那些查看并试图帮助我的人。
谢谢斯科特帮我用那个缺少的支架..现在我有一个通知,即使它编译弹出。“UIKeyboardBoundsUserInfoKey已弃用通知”任何人都知道这意味着什么?当它编译时,我应该担心吗?它出现在的线“NSValue *安勤......”项下的方法行‘keyboardWillShow’

#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** 
+1

你在哪里得到构建错误?双击错误框中的错误通常会让您感到困惑。 –

+0

从哪里以及如何调用scrollTheView:方法? – EmptyStack

+0

请格式化所有的代码 – vikingosegundo

回答

0

听起来像是你缺少一个右括号‘}’或分号‘;’在scrollTheView函数之前的某处。

0

有可能是错误之前你声明scrollTheView,这意味着它无法检测到scrollTheView。在这里看看或发布更多的代码。

0

您在keyboardWillShow:(NSNotification *)notif方法末尾丢失了右括号。

if (scrollAmount >0) { 
    moveViewUp =YES; 
    [self scrollTheView:YES]; 
} 
else { 
    moveViewUp =NO; 
} // This is where the missing bracket should be 
} 

有需要是两个右括号 - 一个用于if声明,一个用于方法 - 但只有一个。

+0

圣洁的废话!谢谢Scott!最快的答复我见过,不仅如此,但解决了它..它编译..但是我也有一个“UIKeyboardBoundsUserInfoKey已弃用通知”任何人都知道这意味着什么?当它编译时,我应该担心吗? – shin