为什么Xcode 4不会对我的UITableViewDataSource协议的不完全实现发出警告? [英] Why does Xcode 4 not throw a warning over my incomplete implementation of the UITableViewDataSource protocol?

查看:88
本文介绍了为什么Xcode 4不会对我的UITableViewDataSource协议的不完全实现发出警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Xcode中使用以下代码声明并不完整地实现自己的协议:


SomeProtocol.h:




  @protocol SomeProtocol< NSObject& 

@required

- (void)someRequiredMethod;

@end




SomeImplementor.h:




  #importSomeProtocol.h

@ :NSObject< SomeProtocol>

@end




SomeImplementor.m:




  #importSomeImplementor.h

@implementation SomeImplementor {//我在此行上收到警告

}

@end

然后Xcode在SomeImplementor.h的 @implementation 行上发出警告,内容如下:


未完成的实施。



协议未执行的方法'someRequiredMethod'。


<但是,如果我不完全实现来自UITableView.h的 UITableViewDataSource 协议,使用以下代码...


SomeClass.h:




  @interface SomeClass:NSObject< UITableViewDataSource> 

@end




SomeClass.m:




  #importSomeClass.h

@implementation SomeClass {//我想我应该在这里收到警告,但我不

}

@end

...然后Xcode很好用,并且不在任何地方显示警告,即使我显然没有从UITableViewDataSource协议实现以下方法:

  @protocol UITableViewDataSource< NSObject> 

@required

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

//行显示。实现者应该*总是*尝试重用单元格,通过设置每个单元格的reuseIdentifier和查询可用的可重用单元格与dequeueReusableCellWithIdentifier:
//单元格获得基于表(分隔符)和数据源(附件视图,编辑控件)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

为什么?我看不出任何理由,这两种情况应该得到不同的对待。

解决方案

这可能是Xcode 4中的一个错误。



它似乎在Xcode 5中是固定的,它会适当地警告你。


If I declare and incompletely implement my own protocol using the following code in Xcode:

SomeProtocol.h:

@protocol SomeProtocol <NSObject>

@required

-(void)someRequiredMethod;

@end

SomeImplementor.h:

#import "SomeProtocol.h"

@interface SomeImplementor : NSObject <SomeProtocol>

@end

SomeImplementor.m:

#import "SomeImplementor.h"

@implementation SomeImplementor { // I get a warning on this line

}

@end

Then Xcode throws a warning on the @implementation line of SomeImplementor.h, that reads as follows:

Incomplete implementation.

Method 'someRequiredMethod' in protocol not implemented.

However, if I incompletely implement the UITableViewDataSource protocol from UITableView.h with the following code...

SomeClass.h:

@interface SomeClass : NSObject <UITableViewDataSource>

@end

SomeClass.m:

#import "SomeClass.h"

@implementation SomeClass  { // I think I should get a warning here, but I don't

}

@end

... then Xcode is fine with it, and doesn't display a warning anywhere, even though I clearly haven't implemented the following methods from the UITableViewDataSource protocol:

@protocol UITableViewDataSource<NSObject>

@required

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

Why? I can't see any reason that these two cases should be treated differently. (And I want my warnings!)

解决方案

This is probably a bug in Xcode 4.

It appears to be fixed in Xcode 5, which warns you appropriately.

这篇关于为什么Xcode 4不会对我的UITableViewDataSource协议的不完全实现发出警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆