Passing parameters on button action:@selector

前端 未结 11 1331
生来不讨喜
生来不讨喜 2020-11-27 17:29

I want to pass the movie url from my dynamically generated button to MediaPlayer:

[button addTarget:self action:@selector(buttonPressed:) withObject:[speaker         


        
11条回答
  •  青春惊慌失措
    2020-11-27 17:58

    I made a solution based in part by the information above. I just set the titleLabel.text to the string I want to pass, and set the titleLabel.hidden = YES

    Like this :

        UIButton *imageclick = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        imageclick.frame = photoframe;
        imageclick.titleLabel.text = [NSString stringWithFormat:@"%@.%@", ti.mediaImage, ti.mediaExtension];
        imageclick.titleLabel.hidden = YES;
    

    This way, there is no need for a inheritance or category and there is no memory leak

提交回复
热议问题