iphone - 奇怪的 Xcode 警告

标签 iphone xcode

我的 Picker 类中有:

- (id)initWithFrame:(CGRect)frame withSender:(id)sender withDate:(NSDate*)date {
    if ((self = [super initWithFrame:frame])) {

datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0 , 0, 0)];
datePicker.date = date;
[sender changeDate:self.datePicker];
datePicker.date = date;

}

在发送者类中:

- (void)changeDate:(id)sender {

//some code

}

这两个方法也在 .h 文件中声明。

但是当我编译时,即使一切正常,xCode 也会告诉我:

no '-changeDate:' method found

引用行[sender changeDate:self.datePicker];

我该怎么做才能让它消失?谢谢!

最佳答案

因为您的发件人具有类型 id,并且对于类型 id,没有调用 (changeDate:) 的方法。因此,如果您想调用 changeDate: 方法,则必须强制转换发送者,或者必须指定特定的类类型。

(MySender *)mySender = (MySender *)sender;

- (id)initWithFrame:(CGRect)frame withSender:(MySender *)sender withDate:(NSDate*)date {

关于iphone - 奇怪的 Xcode 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3793847/

相关文章:

iphone - 更改 TabBarItem 的 ViewController

ios - NSDateFormatter dateFromString 格式为 'hh:mm a' 返回 nil

ios - 将 Storyboard中的连接拖到应用程序委托(delegate)

iphone - iOS 应用程序图标已更新,未在干净的构建/运行中显示

ios - Xcode 5 配置文件不可用

ios - 我如何对 iOS .xcarchive 进行代码签名,以便客户端可以正确辞职? (使用推送通知)

iphone - 应用程序在 iPhone 设备上意外终止,但在模拟器上运行良好

iphone - 裁剪和缩放 CGContext - iOS

iphone - *** -[__NSArrayM 版本] : message sent to deallocated instance

iphone - 读取静态库中的.pch文件