문제

I'm programmatically setting up a NSButton with a target object and I want to pass another object to the called selector.

As far as I know, I can only pass the NSButton instance to a selector, so I'm looking for a way to store a pointer to another object inside of my NSButton.

Is that possible or is there another way to do this?

Example:

[fooButton setAction:NSSelectorFromString(@"fooSelector:")];
[fooButton setTarget:myTargetHandler]

And now, I want to pass "myObject" to myTargetHandler (fooSelector:) when fooButton is clicked.

도움이 되었습니까?

해결책

Have you considered simply subclassing NSButton and adding a property for this? You may even be able to achieve it with a simple category.

There's also a - (NSInteger)tag in every UIControl - maybe that works?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top