【问题标题】:Too many arguments to method call, expected 1, have 2方法调用的参数太多,预期为 1,有 2
【发布时间】:2012-11-03 15:30:11
【问题描述】:

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

代码如下:

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

有什么想法吗?提前致谢。

【问题讨论】:

    标签: iphone xcode ios5 twitter


    【解决方案1】:

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

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

    【讨论】:

    • 啊!完美运行!非常感谢。 :)
    【解决方案2】:

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

    【讨论】:

    • 你的意思是这样的?:[tweetSheet setInitialText:@"%@", [NSString stringWithFormat:@"%@",[[_items objectAtIndex:indexPath.row] objectForKey:@"redirect_url"]]]; 因为它仍然给我同样的错误。
    【解决方案3】:

    我收到此错误是因为 Xcode 自动完成 stringWith...stringWithString: 而不是预期的 stringWithFormat:。花了一些时间找出问题所在,因此请检查您是否确实使用了正确的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      相关资源
      最近更新 更多