Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C: Problems accessing objects in other UIViewControllers
    primarykey
    data
    text
    <p>So I have a Custom UITableViewCell that holds a reference to its containing view controller (the VC that has its table in it). </p> <pre><code>// MyCell.h #import &lt;UIKit/UIKit.h&gt; #import "RootViewController.h" @interface MyCell : UITableViewCell @property (nonatomic, strong) IBOutlet RootViewController *rootViewController; -(IBAction)checkBoxClicked:(UIButton*)sender; // MyCell.m @implementation MyCell @synthesize rootViewController = _rootViewController; -(IBAction)checkBoxClicked:(UIButton*)sender { [self setCheckBoxChecked:!_checkBoxChecked]; [_rootViewController refreshVisibleViewForCellTagged:self.tag]; } </code></pre> <p>In my cell I have a button that changes a variable and then calls a function in my rootViewController. The method is actually called however when I try to access any object in the RootViewController inside of the refreshVisibleViewForCellTagged method they are are '0x0' / nil;</p> <pre><code>// RootViewController.h @interface RootViewController : UIViewController &lt;UITableViewDataSource, UITableViewDelegate&gt; @property (nonatomic, strong) IBOutlet UITableView *myTableView; // RootViewController.m - (void) refreshVisibleViewForCellTagged:(NSInteger)cellTag { UITableView *tableView = self.myTableView; // nil NSIndexPath *indexPath = [self.myTableView indexPathForSelectedRow]; // nil MyCell *selectedCell = (MyCell*)[self.myTableView cellForRowAtIndexPath:indexPath]; // nil if (selectedCell.tag == cellTag) { NSLog(@"Refresh one way."); } else { NSLog(@"Do something else."); } } </code></pre> <p>Can anyone shed some light as to why I cant access any objects/variables in the RootController from within the method 'refreshVisibleViewForCellTagged'?</p> <p>Please and thank you!</p> <p>** My big question is <strong>Why</strong> can't I access any objects when calling a method in a view controller From a different view controller. There is some great programming truth that I am not aware of here, is it a permissions issue? Im not using @class (forward classing) in this instance. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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