Objective-C中不完整的实现错误几乎不需要帮助



我的.m文件中出现了一个"不完整实现"错误,但我不知道如何修复。如果你能给我如何修复的提示,我会发布.h和.m文件。谢谢

显然,我需要提供更多的细节,否则我就不能发布问题了,因为帖子中大部分都是代码,所以这只是一些伪行。

.h文件

#import <UIKit/UIKit.h>
@interface BlogViewController : UIViewController <UIPickerViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
- (IBAction)selectPicturePressed:(id)sender;
- (IBAction)blogPost:(id)sender;
@property (weak, nonatomic) IBOutlet UITextView *commentTextField;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) NSString *username;

@end

.m文件

#import "BlogViewController.h"
#import <Parse/Parse.h>
#import "SWRevealViewController.h"
#import "PhotoViewController.h"
@interface BlogViewController ()
-(void)showErrorView:(NSString *)errorMsg;
@end
@implementation BlogViewController **//Incomplete Implementation**
@synthesize imageView = _imageView;
@synthesize username = _username;
@synthesize commentTextField = _commentTextField;

IBActions只是带有语法糖的常规函数,用于将它们连接到接口生成器,因此您必须在.m文件中实现它们

.m文件:

- (IBAction)selectPicturePressed:(id)sender {
// code here
}
- (IBAction)blogPost:(id)sender {
// and here
}

在给您Incomplete Implementation错误的行上,您可以获得有关所缺少内容的更多详细信息。

您没有粘贴所有的.m,所以任何人都可以猜测您缺少了什么,但是,您的.h声明了您必须实现的2个方法和3个协议。

.m文件必须具有以下两种方法的方法体:

- (IBAction)selectPicturePressed:(id)sender;
- (IBAction)blogPost:(id)sender;

很可能,您已经在这里有了这些,特别是如果这些是通过界面生成器中的Ctrl+Dragging生成的。


但您还必须至少包括您声明的协议中所需的所有方法。

  • UIPickerViewDelegate协议官方文档
  • UINavigationControllerDelegate协议官方文件
  • UIImagePickerControllerDelegate协议官方文件

(我不完全熟悉这些协议,也不确定它们是否真的有任何@required方法。)


.m还有一个私有接口,它声明了一个必须在implementation中实现的方法。

-(void)showErrorView:(NSString *)errorMsg;

您在一个私有接口中声明了这个方法,所以一定要实现这个方法。


无论您缺少什么,如果您只是点击错误/警告,Xcode都会绝对告诉您。Xcode将为您提供它希望在实现中找到但不能找到的方法的名称。

最新更新