{"id":1404,"date":"2022-08-30T15:16:15","date_gmt":"2022-08-30T15:16:15","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/15\/arc-and-popovers-and-delegates-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:15","modified_gmt":"2022-08-30T15:16:15","slug":"arc-and-popovers-and-delegates-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/arc-and-popovers-and-delegates-collection-of-common-programming-errors\/","title":{"rendered":"ARC and Popovers and delegates-Collection of common programming errors"},"content":{"rendered":"<p>i am tearing my hair out, I have migrated my old project to arc and I&#8217;m getting this error popping up : <em>*<\/em> Terminating app due to uncaught exception &#8216;NSGenericException&#8217;, reason: &#8216;-[UIPopoverController dealloc] reached while popover is still visible.&#8217;<\/p>\n<p>I have read through some threads and I&#8217;m confused, some say when using delegates use a weak reference but on the other hand when using popovers use a strong property reference, can someone give me an example of how best to use ARC and delegates with a popover that has a button inside that changes the background colour for example?<\/p>\n<p>From what I&#8217;ve read I keep hearing use an instance variable in my view controller, here it is in my main view controller:<\/p>\n<pre><code>@property (nonatomic, strong) UIPopoverController *currentPopover;\n<\/code><\/pre>\n<p>and the is the method implementation in the main view controller file:<\/p>\n<pre><code>- (IBAction)ShowPopTextColor:(id)sender {\n\nif (currentPopover == nil) {\n\nTimerTextColor *timerTextColor = [[TimerTextColor alloc]init];\ntimerTextColor.delegate =self;\nUIPopoverController *pop = [[UIPopoverController                  alloc]initWithContentViewController:timerTextColor];\n[pop setDelegate:self];\n    [pop setPopoverContentSize:CGSizeMake(320, 240)];\n[pop presentPopoverFromBarButtonItem:sender       permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];\n\n\/\/[pop release];\n\n} else {\n\n   [currentPopover dismissPopoverAnimated:YES];\n    currentPopover = nil;\n}\n\n}\n<\/code><\/pre>\n<p>here is my popup content header:<\/p>\n<pre><code>@protocol colorChooserDelegate\n\n-(void) colorSelected:(UIColor*)thecolor;\n\n@end\n\n@interface TimerTextColor : UIViewController{\n\nid delegate;\n\nIBOutlet UIButton *colorView;\n\n}\n\n- (IBAction)buttonTapped:(id) sender;\n@property (nonatomic,strong) iddelegate;\n@property (nonatomic,strong) UIButton *colorView;\n\n@end\n<\/code><\/pre>\n<p>What am i doing wrong?<\/p>\n<ol>\n<li>\n<p>Assign currentPopover. Call<\/p>\n<pre><code>currentPopover = pop\n<\/code><\/pre>\n<p>after popover creation<\/p>\n<\/li>\n<li>\n<p>you shouldn&#8217;t create a local variable to store the popover controller.<\/p>\n<p>Change this<\/p>\n<pre><code>UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:timerTextColor];\n<\/code><\/pre>\n<p>to<\/p>\n<pre><code>self.currentPopover = [[UIPopoverController alloc] initWithContentViewController:timerTextColor];\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-15 09:09:34. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>i am tearing my hair out, I have migrated my old project to arc and I&#8217;m getting this error popping up : * Terminating app due to uncaught exception &#8216;NSGenericException&#8217;, reason: &#8216;-[UIPopoverController dealloc] reached while popover is still visible.&#8217; I have read through some threads and I&#8217;m confused, some say when using delegates use a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1404","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1404"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1404\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}