xcode 方法调用的参数太多,预期为 1,有 2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13390628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:06:01  来源:igfitidea点击:

Too many arguments to method call, expected 1, have 2

iphonexcodeios5twitter

提问by chrisjr

I am using TWTweetComposeViewControllerfor iOS 5 legacy in my app. For some reason, I am receiving a "Too many arguments to method call, expected 1, have 2" error."I have tried looking for answers in similar questions, but they haven't helped me so far.

TWTweetComposeViewController在我的应用程序中使用iOS 5 旧版。出于某种原因,我收到了一个"Too many arguments to method call, expected 1, have 2" error."我已经尝试在类似问题中寻找答案的消息,但到目前为止他们还没有帮助我。

Here is the code:

这是代码:

TWTweetComposeViewController *tweetSheet =
                [[TWTweetComposeViewController alloc] init];
                [tweetSheet setInitialText:@"%@", [[_items objectAtIndex:indexPath.row] objectForKey:@"redirect_url"]];
                [self presentModalViewController:tweetSheet animated:YES];

Any ideas? Thanks in advance.

有任何想法吗?提前致谢。

Screenshot

截屏

回答by Edwin Iskandar

Like the error says, you have too many arguments. You need to use NSString's stringWithFormat method to create your dynamic string:

就像错误所说的那样,你有太多的论点。您需要使用 NSString 的 stringWithFormat 方法来创建您的动态字符串:

[tweetSheet setInitialText:[NSString stringWithFormat:@"%@", [[_items objectAtIndex:indexPath.row] objectForKey:@"redirect_url"]]];

回答by MaxGabriel

You need to use [NSString stringWithFormat:@"%@",object];to make a format string.

您需要使用[NSString stringWithFormat:@"%@",object];来制作格式字符串。