Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy a separate instance of ViewController Class is affecting previous instance?
    text
    copied!<p><strong>UPDATE - Cause found!</strong>... please read below &amp; suggest the solution:</p> <p>While creating a video to show this issue, I have found why does that happen...</p> <p>Any Control/Element that is defined between <code>#imports</code> &amp; <code>@implementation DetailViewController</code> in <code>.m</code> file is lost by the original detVC when a new instance is created of VC.</p> <p><em>Example:</em> I am including a video that re-creates this issue. As shown, all controls work except a <code>UISegmentedControl</code> &amp; a <code>UILabel</code>.. both of which are defined in <code>DetailViewController.m</code> as:</p> <pre><code>#import "DetailViewController.h" UISegmentedControl *sortcontrol; UILabel *incrementLabel; @implementation DetailViewController </code></pre> <p><strong>Video Link</strong> - <a href="http://www.youtube.com/watch?v=2ABdK0LkGiA" rel="nofollow">http://www.youtube.com/watch?v=2ABdK0LkGiA</a></p> <p>I think we are pretty close.. Waiting for the answer!!</p> <p>P.S.: I think this info is enough can lead us to the solution, but if needed I can share the code too.</p> <hr> <p>EARLIER:</p> <p>There's a detailViewController (detVC) in our app which is normally 'pushed' from a UITableViewController.</p> <p>Now we are also implementing Push Notifications which would 'modally' present the same detVC whenever the notification arrives, which in turn can happen over any view controller.</p> <p>It works all fine until the detVC through notification is presented while another instance of detVC was already the active view controller (pushed earlier through TableView).</p> <p>The problem happens when the presented detVC is dismissed - the pushed detVC 'looses' control of about everything - It is not pointing to the same data as earlier &amp; even the <code>UISegmentedControl</code> on Navigation Toolbar points to <code>-1</code> index on pressing any index!</p> <p>Why does such thing happen when we are creating a separate instance of detVC? Why does it affect the earlier detVC? How can it be resolved / What about Objective C needs to be learned here? (FYI, we are using ARC in the project)</p> <p>Thanks</p> <hr> <p>EDIT - Some code:</p> <p>When Pushed:</p> <pre><code>ProductDetailViewController *detailViewController = [[ProductDetailViewController alloc] init]; detailViewController.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:detailViewController animated:YES]; detailViewController.serverOffset=serverOffset; detailViewController.prdctIndex = indexPath.row; </code></pre> <p>When presented through Notification:</p> <pre><code>- (void)displaySingleProduct:(NSDictionary*)userInfo{ ProductDetailViewController *onePrdVC = [[ProductDetailViewController alloc] init]; UINavigationController *addNav = [[UINavigationController alloc] initWithRootViewController:onePrdVC]; onePrdVC.justOne=YES; onePrdVC.onePrdIDtoLoad=[[[userInfo valueForKey:@"prd"] valueForKey:@"id"] intValue]; [self.navigationController presentModalViewController:addNav animated:YES]; } </code></pre> <p>There is a <code>Product</code> class in detVC which gets the data from the values stored at the prdctIndex row in the SQLite table.</p> <p>After dismissing the presented detVC through notification, the <code>Product</code> class of the pushed detVC starts pointing to the row which was used for <code>Product</code> class in presented detVC. And there is no such code in <code>viewDidAppear</code> which would alter <code>Product</code> class.</p> <p>So, this, <code>UISegmentedControl</code> issue mentioned above &amp; some other problems are causing the pain! Basically, the whole detVC acts weird - which re-works if we just pop &amp; re-push it!</p> <hr> <p><strong>EDIT 2</strong></p> <p>I have more info on it which could lead to the cause. If I run <code>viewDidLoad</code> on <code>viewDidAppear</code> like this:</p> <pre><code>if (!justOne) { aProduct = [allProducts getProduct:(prdctIndex+1) one:NO]; [self viewDidLoad]; [self populateDetails]; } </code></pre> <p>the pushed detVC regains the control &amp; every element/control starts re-working as expected (but not in the ideal way). So, it is quite clear that the separate instance of presented detVC does messes up the earlier pushed detVC &amp; a re-setting up of all the controls / pointers is required through <code>viewDidLoad</code>.</p> <p>Can any helpful conclusion can be derived from this info?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload