目标C在方法原型错误之后预期';'

时间:2015-03-08 23:08:32

标签: objective-c xcode xcode6

我的代码存在问题

#import <Foundation/Foundation.h>

@protocol ServiceDelegate <NSObject>


-(void)serviceFinished:(id)service withError:(BOOL)error {
    if (!error)
        [searchResults removeAllObjects];

        for (NSDictionary *movie in [service results]) {
            [searchResults addObject:[movie valueForKey:@"title"]];
        }

        [[self tableView] reloadData];
    }


@end
它一直告诉我要放一个;而不是{在这一行

-(void)serviceFinished:(id)service withError:(BOOL)error {

但是,如果我替换{那么代码中断并且不起作用。并告诉我第二行代码

if (!error) {

if有错误&#34;预期标识符或&#39;(&#39;

关于如何使其发挥作用的任何想法?

1 个答案:

答案 0 :(得分:0)

您的界面代码:

#import <UIKit/UIKit.h>

@interface FilmTableViewController : UITableViewController

@end

@interface initWithStyle : NSString
- (void)UITableViewStyle:(NSString*);

@end

错误 。它应该是:

#import <UIKit/UIKit.h>

@interface FilmTableViewController : UITableViewController

- (id)initWithStyle:(UITableViewStyle)style;

@end

@interface应始终后跟类名 - 以及:和超类名称,以及带角度括号内的采用协议(并以逗号分隔) ) - 。 方法的接口声明与实现(定义)中的函数头相同,末尾带有分号(;)(与C函数的规则相同,但必须是使用@interface... / @end对。)

附录:您提到iti是.m文件似乎导致错误;但是,- (id)initWithStyle:(UITableViewStyle)style的方法定义看起来不错......那么,Xcode指向哪一行?什么是实际的错误消息?

附录2:您错过了}-tableView:cellForRowAtIndexPath:的方法正文(initWithStyle:之后)之间的结束return cell;,这就是编译器没有将方法定义解释为正确代码的原因。你的代码坏了。