gpt4 book ai didi

ios - 为什么 Xcode 4 没有对我不完整的 UITableViewDataSource 协议(protocol)实现发出警告?

转载 作者:可可西里 更新时间:2023-11-01 04:44:17 37 4
gpt4 key购买 nike

如果我在 Xcode 中使用以下代码声明并未完全实现我自己的协议(protocol):

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

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

Incomplete implementation.

Method 'someRequiredMethod' in protocol not implemented.

但是,如果我使用以下代码未完全实现 UITableView.h 中的 UITableViewDataSource 协议(protocol)...

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

...那么 Xcode 就可以了,并且不会在任何地方显示警告,即使我显然没有从 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;

为什么?我看不出有任何理由应该区别对待这两个案例。 (我想要我的警告!)

最佳答案

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

它似乎已在 Xcode 5 中修复,它会适本地警告您。

关于ios - 为什么 Xcode 4 没有对我不完整的 UITableViewDataSource 协议(protocol)实现发出警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17453434/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com