0

我有一个问题..我想从这个函数传递选定的段索引变量:

-(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];

我尝试了很多东西,但我没有成功..你能帮帮我吗?

非常感谢...

4

1 回答 1

0

假设流派应该是整数,并假设insertNameinsertArtistinsertTitle是 的实例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];
    }
}

我建议阅读如何格式化NSStringObjective C 方法和消息传递的入门

于 2013-03-04T19:03:49.477 回答