Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将对象的实例传递给方法_Iphone_Objective C_Object_Methods_Arguments - Fatal编程技术网

Iphone 将对象的实例传递给方法

Iphone 将对象的实例传递给方法,iphone,objective-c,object,methods,arguments,Iphone,Objective C,Object,Methods,Arguments,我有这个方法: - (void)postDictionary:(NSDictionary *)dictionary toURL:(NSURL *)url forDelegate:(id)delegate withIdentifier:(NSString *)identifier; 我想将一个对象的实例传递给此方法,然后调用如下内容: if ([delegate respondsToSelector:@selector(didFinishDownload:)]) { [delegate

我有这个方法:

- (void)postDictionary:(NSDictionary *)dictionary toURL:(NSURL *)url forDelegate:(id)delegate withIdentifier:(NSString *)identifier;
我想将一个对象的实例传递给此方法,然后调用如下内容:

if ([delegate respondsToSelector:@selector(didFinishDownload:)]) {
    [delegate performSelector:@selector(didFinishDownload:) withObject:@"test"];
}
我想我必须将对象的指针传递给该方法

我想我得用*、**和&。但是我不知道在哪里我必须使用哪一个

你能帮帮我吗

侧扫

我猜-voidpostDictionary:NSDictionary*dictionary toURL:NSURL*url for delegate:iddelegate with identifier:NSString*identifier;是您声明的方法

你可以


-voidpostDictionary:NSDictionary*dictionary toURL:NSURL*delegate的url:iddelegate with identifier:NSString*identifier with Object:idobj

例如,为什么你不能轻松地完成

if ([delegate respondsToSelector:@selector(didFinishDownload:)]) {
    [delegate performSelector:@selector(didFinishDownload:) withObject:identifier];
}

为什么你说你需要做一种指针操作?

你会发现目标C中的所有对象都被指针引用。因此,当您声明NSString时,可以执行以下操作:

NSString *myString = @"testString";
以同样的方式,执行alloc init创建新对象将返回指针。您可以直接将指针传递给该方法

if ([delegate respondsToSelector:@selector(didFinishDownload:)]) {
[delegate performSelector:@selector(didFinishDownload:) withObject:myString];

}

哦,我想我不清楚我想要什么。我声明了'-voidpostDictionary:NSDictionary*字典教程:NSURL*delegate:iddelegate with identifier:NSString*identifier;'委托应该是我传递的对象的实例。但我可以这样称呼它吗?我不需要使用指针之类的东西来调用传递的“委托”的方法吗?不,实际上对象本身的实例就是指针。您可以直接发送该实例。此问题可以删除。非常抱歉,我刚刚使用了错误类型的对象,因此没有调用选择器。