Objective c 将变量从一个函数传递到另一个函数

Objective c 将变量从一个函数传递到另一个函数,objective-c,variables,Objective C,Variables,我有个问题。。我想通过此函数传递选定的分段集索引变量: -(IBAction)segControllIndex:(id)sender { UISegmentedControl *segmentedControl = (UISegmentedControl *)sender; int segValue = [segmentedControl selectedSegmentIndex]; 到这里: NSString *strURL = [NSString stringWithFo

我有个问题。。我想通过此函数传递选定的分段集索引变量:

-(IBAction)segControllIndex:(id)sender {

    UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
   int segValue = [segmentedControl selectedSegmentIndex];
到这里:

 NSString *strURL = [NSString stringWithFormat:
 @"http://phpFile.php?Name=%1@&Artist=%2@&Titel=%3@&Genere=%4@", 
 insertName,insertArtist,insertTitle, PASSED VALUE];
我尝试了很多事情,但都没有成功。。 你能帮我吗


非常感谢…

假设类型应该是整数,假设
insertName
insertist
insertTitle
NSString
的实例:

// define this method in your class
-(void)someMethod:(int)passedValue {
    NSString *strURL = [NSString stringWithFormat:@"http://phpFile.php?Name=%@&Artist=%@&Titel=%@&Genere=%d", insertName,insertArtist,insertTitle, passedValue];

    // do your work
}
这样,您可以调用:

-(IBAction)segControllIndex:(id)sender {
    // I would recommend validating 'sender' first
    // withou knowing anything else about your calls, here is one example
    if ( [sender isKindOfClass:[UISegmentedControl class]] ) {
        UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
        int segValue = [segmentedControl selectedSegmentIndex];

        [self someMethod:segValue];
    }
}

我建议,a。

传递的值为int。因此使用%d,编写您尝试过的完整函数。阅读Objective-C的基础知识,因为这是简单的。即使您的第一个方法也会传入一个参数(发送方)…我想将segValue传递给另一个函数…我解决了这个问题,谢谢!你的最后一个例子在另一方面对我很有帮助。。谢谢大家!@卡斯滕格拉夫很高兴我这么聪明。