Objective c 方法调用的参数太多

Objective c 方法调用的参数太多,objective-c,iphone,xcode,compiler-errors,arguments,Objective C,Iphone,Xcode,Compiler Errors,Arguments,我正在尝试使用appDelegate中的NSString设置twitter消息在我的应用程序中应该说的内容的初始文本。请在此处查看代码: NSString *tweet; tweet=[MyWebFunction tweet:appDelegate.stadium_id]; if([deviceType hasPrefix:@"5."]){ // Create the view controller TWTweetComposeViewController *twi

我正在尝试使用appDelegate中的NSString设置twitter消息在我的应用程序中应该说的内容的初始文本。请在此处查看代码:

    NSString *tweet;
tweet=[MyWebFunction tweet:appDelegate.stadium_id];


if([deviceType hasPrefix:@"5."]){

    // Create the view controller
    TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];

    [twitter setInitialText:@"@%",tweet];
问题是,twitter setInitialText中是否存在错误,即方法调用的参数太多,预期为1,实际为2

非常感谢您的帮助。:)


试试
[twitter setInitialText:tweet]

如果您确实需要格式化文本来处理更复杂的情况,请尝试


[twitter setInitialText:[NSString stringWithFormat:@“%@”,tweet]]

尝试
[twitter setInitialText:tweet]

如果您确实需要格式化文本来处理更复杂的情况,请尝试


[twitter setInitialText:[NSString stringWithFormat:@“%@”,tweet]]

tweetcomposeviewcontroller
方法
setInitialText
只接受一个参数,类型为
NSString*
。您不能像使用
NSString
方法
stringWithFormat
一样,简单地格式化传递给方法的任何和所有
NSString
变量(我想,这就是您看到语法
[NSString stringWithFormat:@“%@”,myString]

在您的情况下,您只需呼叫:

[twitter setInitialText:tweet];
或致电:

[twitter setInitialText:[NSString stringWithFormat:@"%@", tweet]]
编辑
为了进一步理解,我觉得有必要补充一点,即当方法的声明以
结尾时,它只接受数量可变的参数(例如
stringWithFormat

例如,在文档中查找
NSString
会发现
stringWithFormat
声明如下:

+(id) stringWithFormat:(NSString *)format, ...;
+(id) arrayWithObjects:(id)firstObj, ...;
类似地,
NSArray
中的
arrayWithObjects
声明如下:

+(id) stringWithFormat:(NSString *)format, ...;
+(id) arrayWithObjects:(id)firstObj, ...;
哪一个会使用,例如:

NSString* myString1 = @"foo";
NSString* myString2 = @"bar";
NSNumber* myNumber = [NSNumber numberWithInt:42];
NSArray* myArray = [NSArray arrayWithObjects:myString1, myString2, myNumber, nil];

tweetcomposeviewcontroller
方法
setInitialText
只接受一个参数,类型为
NSString*
。您不能像使用
NSString
方法
stringWithFormat
一样,简单地格式化传递给方法的任何和所有
NSString
变量(我想,这就是您看到语法
[NSString stringWithFormat:@“%@”,myString]

在您的情况下,您只需呼叫:

[twitter setInitialText:tweet];
或致电:

[twitter setInitialText:[NSString stringWithFormat:@"%@", tweet]]
编辑
为了进一步理解,我觉得有必要补充一点,即当方法的声明以
结尾时,它只接受数量可变的参数(例如
stringWithFormat

例如,在文档中查找
NSString
会发现
stringWithFormat
声明如下:

+(id) stringWithFormat:(NSString *)format, ...;
+(id) arrayWithObjects:(id)firstObj, ...;
类似地,
NSArray
中的
arrayWithObjects
声明如下:

+(id) stringWithFormat:(NSString *)format, ...;
+(id) arrayWithObjects:(id)firstObj, ...;
哪一个会使用,例如:

NSString* myString1 = @"foo";
NSString* myString2 = @"bar";
NSNumber* myNumber = [NSNumber numberWithInt:42];
NSArray* myArray = [NSArray arrayWithObjects:myString1, myString2, myNumber, nil];
你刚刚把你的“@”和“%”搞错了

[twitter setInitialText:@"**%@**",tweet];
你刚刚把你的“@”和“%”搞错了

[twitter setInitialText:@"**%@**",tweet];