Objective-C: Popover seems to be always nil The 2019 Stack Overflow Developer Survey Results Are InShortcuts in Objective-C to concatenate NSStringsConstants in Objective-CHow do I create delegates in Objective-C?What is a typedef enum in Objective-C?How do I sort an NSMutableArray with custom objects in it?How do I check if a string contains another string in Objective-C?insertSubView: is not showing my viewsProblem in creating new window in cocoa Mac on Button click-[ViewAController doLogin:]: unrecognized selector sent to instance 0x6901bc0NSURL return nil?
Where to refill my bottle in India?
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Is this app Icon Browser Safe/Legit?
Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?
Why is the maximum length of OpenWrt’s root password 8 characters?
Time travel alters history but people keep saying nothing's changed
What is the motivation for a law requiring 2 parties to consent for recording a conversation
Does a dangling wire really electrocute me if I'm standing in water?
What is the closest word meaning "respect for time / mindful"
Is there any way to tell whether the shot is going to hit you or not?
How to obtain Confidence Intervals for a LASSO regression?
Protecting Dualbooting Windows from dangerous code (like rm -rf)
How to save as into a customized destination on macOS?
Pokemon Turn Based battle (Python)
Is three citations per paragraph excessive for undergraduate research paper?
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
Origin of "cooter" meaning "vagina"
Can a flute soloist sit?
How to deal with fear of taking dependencies
What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?
What does ひと匙 mean in this manga and has it been used colloquially?
If a Druid sees an animal’s corpse, can they wild shape into that animal?
Have you ever entered Singapore using a different passport or name?
How technical should a Scrum Master be to effectively remove impediments?
Objective-C: Popover seems to be always nil
The 2019 Stack Overflow Developer Survey Results Are InShortcuts in Objective-C to concatenate NSStringsConstants in Objective-CHow do I create delegates in Objective-C?What is a typedef enum in Objective-C?How do I sort an NSMutableArray with custom objects in it?How do I check if a string contains another string in Objective-C?insertSubView: is not showing my viewsProblem in creating new window in cocoa Mac on Button click-[ViewAController doLogin:]: unrecognized selector sent to instance 0x6901bc0NSURL return nil?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm currently writing a plugin for SketchApp with cocoa.
I try to use a NSPopover there, that should get triggered by an IBAction when clicking on a button. Problem is: the popover does not show up, and when inspecting the variable, that should hold the popover, it is nil.
I created the NSPopover in the Interface Builder, so not programmatically in code; then defined an IBOutlet binding in my linked classes header file; and finally use this variable inside my implementation class.
Here is my source code:
MyComponent.h
// imports skipped...
@interface
@property (nonatomic, weak) IBOutlet NSTextField *componentDescription;
@property (nonatomic, weak) IBOutlet NSTextField *componentGuid;
@property (nonatomic, weak) IBOutlet NSButton *guidCopyButton;
@property (nonatomic, weak) IBOutlet NSPopover *popover;
-(IBAction)onCopyButton_Clicked:(id)sender;
@end
MyComponent.m
-(IBAction)onCopyButton_Clicked:(id)sender
// copy stuff to clipboard
// [...]
// show copied popover
[_popover showRelativeToRect:[sender bounds]
ofView:sender
preferredEdge:NSMinYEdge];
In my xib-view-file, I linked the NSPopover-Object to the IBOutlet NSPopover *popover;. But when inspecting _popover in my class implementation it is always nil.
objective-c cocoa sketchapp-plugin
add a comment |
I'm currently writing a plugin for SketchApp with cocoa.
I try to use a NSPopover there, that should get triggered by an IBAction when clicking on a button. Problem is: the popover does not show up, and when inspecting the variable, that should hold the popover, it is nil.
I created the NSPopover in the Interface Builder, so not programmatically in code; then defined an IBOutlet binding in my linked classes header file; and finally use this variable inside my implementation class.
Here is my source code:
MyComponent.h
// imports skipped...
@interface
@property (nonatomic, weak) IBOutlet NSTextField *componentDescription;
@property (nonatomic, weak) IBOutlet NSTextField *componentGuid;
@property (nonatomic, weak) IBOutlet NSButton *guidCopyButton;
@property (nonatomic, weak) IBOutlet NSPopover *popover;
-(IBAction)onCopyButton_Clicked:(id)sender;
@end
MyComponent.m
-(IBAction)onCopyButton_Clicked:(id)sender
// copy stuff to clipboard
// [...]
// show copied popover
[_popover showRelativeToRect:[sender bounds]
ofView:sender
preferredEdge:NSMinYEdge];
In my xib-view-file, I linked the NSPopover-Object to the IBOutlet NSPopover *popover;. But when inspecting _popover in my class implementation it is always nil.
objective-c cocoa sketchapp-plugin
add a comment |
I'm currently writing a plugin for SketchApp with cocoa.
I try to use a NSPopover there, that should get triggered by an IBAction when clicking on a button. Problem is: the popover does not show up, and when inspecting the variable, that should hold the popover, it is nil.
I created the NSPopover in the Interface Builder, so not programmatically in code; then defined an IBOutlet binding in my linked classes header file; and finally use this variable inside my implementation class.
Here is my source code:
MyComponent.h
// imports skipped...
@interface
@property (nonatomic, weak) IBOutlet NSTextField *componentDescription;
@property (nonatomic, weak) IBOutlet NSTextField *componentGuid;
@property (nonatomic, weak) IBOutlet NSButton *guidCopyButton;
@property (nonatomic, weak) IBOutlet NSPopover *popover;
-(IBAction)onCopyButton_Clicked:(id)sender;
@end
MyComponent.m
-(IBAction)onCopyButton_Clicked:(id)sender
// copy stuff to clipboard
// [...]
// show copied popover
[_popover showRelativeToRect:[sender bounds]
ofView:sender
preferredEdge:NSMinYEdge];
In my xib-view-file, I linked the NSPopover-Object to the IBOutlet NSPopover *popover;. But when inspecting _popover in my class implementation it is always nil.
objective-c cocoa sketchapp-plugin
I'm currently writing a plugin for SketchApp with cocoa.
I try to use a NSPopover there, that should get triggered by an IBAction when clicking on a button. Problem is: the popover does not show up, and when inspecting the variable, that should hold the popover, it is nil.
I created the NSPopover in the Interface Builder, so not programmatically in code; then defined an IBOutlet binding in my linked classes header file; and finally use this variable inside my implementation class.
Here is my source code:
MyComponent.h
// imports skipped...
@interface
@property (nonatomic, weak) IBOutlet NSTextField *componentDescription;
@property (nonatomic, weak) IBOutlet NSTextField *componentGuid;
@property (nonatomic, weak) IBOutlet NSButton *guidCopyButton;
@property (nonatomic, weak) IBOutlet NSPopover *popover;
-(IBAction)onCopyButton_Clicked:(id)sender;
@end
MyComponent.m
-(IBAction)onCopyButton_Clicked:(id)sender
// copy stuff to clipboard
// [...]
// show copied popover
[_popover showRelativeToRect:[sender bounds]
ofView:sender
preferredEdge:NSMinYEdge];
In my xib-view-file, I linked the NSPopover-Object to the IBOutlet NSPopover *popover;. But when inspecting _popover in my class implementation it is always nil.
objective-c cocoa sketchapp-plugin
objective-c cocoa sketchapp-plugin
edited Mar 8 at 9:24
Dale Burrell
3,47952655
3,47952655
asked Jul 27 '18 at 16:00
jlangjlang
362117
362117
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Okay, after tweeking things around a bit, I guess I finally understood what went wrong. After changing the memory mode from @property (nonatomic, weak) NSPopover *popover; to ... (nonatomic, strong) ...; the instance is not nil anymore.
I think the difference to the NSButton (for example) here is, that the button is used in the xib template, so the button's reference does not get cleaned up. The Popover however is not directly "used", so it may gets cleaned up, before it could get actually used. So, changing it from weak to strong seems to be the point here.
However: Does this tweak have unexpected / unintended side effects I probably want to address somehow? Do I have to care for the destruction on my own for the popover now?
1
References to non primary objects in XIBs generally need to be strong. If you connected the outlet by dragging from IB rather than writing it in code it should have done that.MyComponentowns the popover so it’s correct that it should be strong.
– Warren Burton
Jul 28 '18 at 8:56
Thanks a lot for the clarification! I'm new to cocoa and in general C / Objective C, so this was an important thing for me to realize for future :)
– jlang
Jul 28 '18 at 8:59
Yep. It’s not easy to work out sometimes. The buttons and text fields can be weak because they are part of a view hierarchy but your popover that I assume is floating as second object in the XIB needs an owner. :-)
– Warren Burton
Jul 28 '18 at 9:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51561619%2fobjective-c-popover-seems-to-be-always-nil%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Okay, after tweeking things around a bit, I guess I finally understood what went wrong. After changing the memory mode from @property (nonatomic, weak) NSPopover *popover; to ... (nonatomic, strong) ...; the instance is not nil anymore.
I think the difference to the NSButton (for example) here is, that the button is used in the xib template, so the button's reference does not get cleaned up. The Popover however is not directly "used", so it may gets cleaned up, before it could get actually used. So, changing it from weak to strong seems to be the point here.
However: Does this tweak have unexpected / unintended side effects I probably want to address somehow? Do I have to care for the destruction on my own for the popover now?
1
References to non primary objects in XIBs generally need to be strong. If you connected the outlet by dragging from IB rather than writing it in code it should have done that.MyComponentowns the popover so it’s correct that it should be strong.
– Warren Burton
Jul 28 '18 at 8:56
Thanks a lot for the clarification! I'm new to cocoa and in general C / Objective C, so this was an important thing for me to realize for future :)
– jlang
Jul 28 '18 at 8:59
Yep. It’s not easy to work out sometimes. The buttons and text fields can be weak because they are part of a view hierarchy but your popover that I assume is floating as second object in the XIB needs an owner. :-)
– Warren Burton
Jul 28 '18 at 9:03
add a comment |
Okay, after tweeking things around a bit, I guess I finally understood what went wrong. After changing the memory mode from @property (nonatomic, weak) NSPopover *popover; to ... (nonatomic, strong) ...; the instance is not nil anymore.
I think the difference to the NSButton (for example) here is, that the button is used in the xib template, so the button's reference does not get cleaned up. The Popover however is not directly "used", so it may gets cleaned up, before it could get actually used. So, changing it from weak to strong seems to be the point here.
However: Does this tweak have unexpected / unintended side effects I probably want to address somehow? Do I have to care for the destruction on my own for the popover now?
1
References to non primary objects in XIBs generally need to be strong. If you connected the outlet by dragging from IB rather than writing it in code it should have done that.MyComponentowns the popover so it’s correct that it should be strong.
– Warren Burton
Jul 28 '18 at 8:56
Thanks a lot for the clarification! I'm new to cocoa and in general C / Objective C, so this was an important thing for me to realize for future :)
– jlang
Jul 28 '18 at 8:59
Yep. It’s not easy to work out sometimes. The buttons and text fields can be weak because they are part of a view hierarchy but your popover that I assume is floating as second object in the XIB needs an owner. :-)
– Warren Burton
Jul 28 '18 at 9:03
add a comment |
Okay, after tweeking things around a bit, I guess I finally understood what went wrong. After changing the memory mode from @property (nonatomic, weak) NSPopover *popover; to ... (nonatomic, strong) ...; the instance is not nil anymore.
I think the difference to the NSButton (for example) here is, that the button is used in the xib template, so the button's reference does not get cleaned up. The Popover however is not directly "used", so it may gets cleaned up, before it could get actually used. So, changing it from weak to strong seems to be the point here.
However: Does this tweak have unexpected / unintended side effects I probably want to address somehow? Do I have to care for the destruction on my own for the popover now?
Okay, after tweeking things around a bit, I guess I finally understood what went wrong. After changing the memory mode from @property (nonatomic, weak) NSPopover *popover; to ... (nonatomic, strong) ...; the instance is not nil anymore.
I think the difference to the NSButton (for example) here is, that the button is used in the xib template, so the button's reference does not get cleaned up. The Popover however is not directly "used", so it may gets cleaned up, before it could get actually used. So, changing it from weak to strong seems to be the point here.
However: Does this tweak have unexpected / unintended side effects I probably want to address somehow? Do I have to care for the destruction on my own for the popover now?
answered Jul 28 '18 at 8:41
jlangjlang
362117
362117
1
References to non primary objects in XIBs generally need to be strong. If you connected the outlet by dragging from IB rather than writing it in code it should have done that.MyComponentowns the popover so it’s correct that it should be strong.
– Warren Burton
Jul 28 '18 at 8:56
Thanks a lot for the clarification! I'm new to cocoa and in general C / Objective C, so this was an important thing for me to realize for future :)
– jlang
Jul 28 '18 at 8:59
Yep. It’s not easy to work out sometimes. The buttons and text fields can be weak because they are part of a view hierarchy but your popover that I assume is floating as second object in the XIB needs an owner. :-)
– Warren Burton
Jul 28 '18 at 9:03
add a comment |
1
References to non primary objects in XIBs generally need to be strong. If you connected the outlet by dragging from IB rather than writing it in code it should have done that.MyComponentowns the popover so it’s correct that it should be strong.
– Warren Burton
Jul 28 '18 at 8:56
Thanks a lot for the clarification! I'm new to cocoa and in general C / Objective C, so this was an important thing for me to realize for future :)
– jlang
Jul 28 '18 at 8:59
Yep. It’s not easy to work out sometimes. The buttons and text fields can be weak because they are part of a view hierarchy but your popover that I assume is floating as second object in the XIB needs an owner. :-)
– Warren Burton
Jul 28 '18 at 9:03
1
1
References to non primary objects in XIBs generally need to be strong. If you connected the outlet by dragging from IB rather than writing it in code it should have done that.
MyComponent owns the popover so it’s correct that it should be strong.– Warren Burton
Jul 28 '18 at 8:56
References to non primary objects in XIBs generally need to be strong. If you connected the outlet by dragging from IB rather than writing it in code it should have done that.
MyComponent owns the popover so it’s correct that it should be strong.– Warren Burton
Jul 28 '18 at 8:56
Thanks a lot for the clarification! I'm new to cocoa and in general C / Objective C, so this was an important thing for me to realize for future :)
– jlang
Jul 28 '18 at 8:59
Thanks a lot for the clarification! I'm new to cocoa and in general C / Objective C, so this was an important thing for me to realize for future :)
– jlang
Jul 28 '18 at 8:59
Yep. It’s not easy to work out sometimes. The buttons and text fields can be weak because they are part of a view hierarchy but your popover that I assume is floating as second object in the XIB needs an owner. :-)
– Warren Burton
Jul 28 '18 at 9:03
Yep. It’s not easy to work out sometimes. The buttons and text fields can be weak because they are part of a view hierarchy but your popover that I assume is floating as second object in the XIB needs an owner. :-)
– Warren Burton
Jul 28 '18 at 9:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51561619%2fobjective-c-popover-seems-to-be-always-nil%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown