हाँ:
-(IBAction)pressedButton:(id)sender
{
id value = [sender valueForKey:key];
}
ध्यान दें कि यदि आप एक उपयोगकर्ता का उपयोग नहीं कर सकते हैं परिभाषित किया जाता है भागो समय विशेषता, जब तक आप UIButton उपवर्ग और एक मजबूत संपत्ति के रूप में जोड़ने, उदाहरण के लिए
@interface UINamedButton : UIButton
@property (strong) NSString *keyName;
@end
यदि आप उपयोगकर्ता परिभाषित रन टाइम विशेषता सेट करते हैं, और आपने यह नहीं किया है, तो एक्सकोड दुर्भाग्यवश दुर्भाग्य से क्रैश हो जाएगा।
तो आप
-(IBAction)clicked:(UIControl *)sender
{
NSString *test = @"???";
if ([sender respondsToSelector:@selector(keyName)])
test = [sender valueForKey:@"keyName"];
NSLog(@"the value of keyName is ... %@", test);
// if you FORGOT TO SET the keyName value in storyboard, that will be NULL
// if it's NOT a UINamedButton button, you'll get the "???"
// and for example...
[self performSegueWithIdentifier:@"idUber" sender:sender];
// ...the prepareForSegue could then use that value in the button.
// note that a useful alternative to
// if ([sender respondsToSelector:@selector(stringTag)])
// is...
// if ([sender respondsToSelector:NSSelectorFromString(@"stringTag")])
}
की तरह है कि मूल्य प्राप्त कर सकते हैं