I have 2 viewcontrollers - one is a tableview and the other is a normal viewcontroller. I want pass data from the second viewcontroller to a tableview controller by using delegates. I have created a delegate and delegatemethod in viewcontroller and implemented delegatemethod in the tableview controller. The problem is that I am getting data to the array but tableview is not reloading. Why?
Can anyone help with this problem? Thanks in advance.
#import "TableViewController.h"
#interface TableViewController ()<name>{
NSMutableArray *data;
}
#end
#implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
data = [NSMutableArray array];
[self.tableView reloadData];
}
- (IBAction)callingSecondView:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
ViewController *var = [storyboard instantiateViewControllerWithIdentifier:#"vc"];
var.delegate = self;
[self.navigationController pushViewController:var animated:YES];
}
-(void)getdata:(NSString *)name{
[data addObject:name];
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
if (cell != nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"cell"];
}
cell.textLabel.text = [data objectAtIndex:indexPath.row];
return cell;
}
And I am creating delegate a object and protocol in ViewController.h
#import <UIKit/UIKit.h>
#protocol name <NSObject>
-(void)getdata : (NSString *)name;
#end
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *txt;
- (IBAction)done:(id)sender;
#property(nonatomic,retain) id<name> delegate;
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize delegate;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)done:(id)sender {
[delegate getdata:self.txt.text];
[self.navigationController popToRootViewControllerAnimated:YES];
}
#end
I think the first VC don't reloadData because it's not the visible VC. Try reloadData when the VC willAppear.
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
Related
I have a UIViewController and a UITableViewController.
In ViewController I have a UIButton and UITextfield, when I press button it will navigate to TableViewController with static data in the tableview like (iPhone 5S, iPhone 6, iPhone 6S, iPhone 7), when I select any of the row it should be displayed in the textfield of ViewController. Tried but cannot get this one. Help me to solve this. below is my code:
ViewController.h
————————————————
#import <UIKit/UIKit.h>
#import "Utility.h"
#interface ViewController : UIViewController
- (IBAction)oneButtonClicked:(id)sender;
#property (strong, nonatomic) IBOutlet UITextField *txtOne;
ViewController.m
————————————————
//Can't understand what to do in this viewcontroller.
TableViewController.h
—————————————————————-
#import <UIKit/UIKit.h>
#import "Utility.h"
#interface FamilyDetailsViewController : UITableViewController
#end
TableViewController.m
—————————————————————-
#import "FamilyDetailsViewController.h"
#interface FamilyDetailsViewController ()
{
NSArray *arr;
}
#end
#implementation FamilyDetailsViewController
- (void)viewDidLoad {
[super viewDidLoad];
arr=[[NSArray alloc]initWithObjects:#"Parent",#"Grandparent",#"Sibling",#"Child",#"Other", nil];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[arr objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController popViewControllerAnimated:YES];
}
in `ViewControllerB.h` which is a TableViewController declare a delegate to pass the data to ViewControllerA and create a delegate object
#import <UIKit/UIKit.h>
#protocol DataDelegate <NSObject>
- (void)passData:(NSString *)data;
#end
#interface ViewControllerB : UIViewController
#property (weak, nonatomic) id<DataDelegate> delegate;
#end
in ViewControllerB.m file
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedText = titleArray[indexPath.row];
if [self.delegate respondsToSelector:#selector(passData:)]) {
[self.delegate passData:"hello"];
}
[self.navigationController popViewControllerAnimated:YES];
}
**in ViewControllerA**
#import "ViewControllerA.h"
#import "ViewControllerB.h"
#interface ViewControllerA () <DataDelegate>
#property (strong, nonatomic) ViewControllerB *viewControllerB;
#end
#implementation ViewControllerA
- (void)viewDidLoad {
_viewControllerB.delegate = self;
}
- (void)passData:(NSString *)data {
self.textField.text = data
}
Try Using NSNotification. Pass data back to ViewController with NSNotification. First register a notification in viewWillAppear of ViewController.
Try below code:
In ViewController:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(getTextFromTable:) name:#"PassTextBackToViewController" object:nil];
}
Then define Method in ViewController like this:
-(void)getTextFromTable:(NSNotification *)notification
{
[self.textField setText:[notification.userInfo valueForKey:#"cellText"]];
}
And in tableView's didSelectRowAtIndexPath method, Post the notification:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:cell.textLabel.text,#"cellText", nil]
[[NSNotificationCenter defaultCenter]postNotificationName:#"PassTextBackToViewController" object:dictionary];
[self.navigationController popViewControllerAnimated:YES];
}
Make Sure, Notification's name must be same in both ViewController and
TableViewController
Follow this:
In AppDelegate.h
#property (strong, nonatomic) NSString *selectedText;
In ViewController.m
-(void)viewWillAppear:(BOOL)animated
{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
txtOne.text = appDelegate.selectedText;
}
Make appDelegate.selectedText = #"" while navigating to UITableViewController Class.
In FamilyDetailsViewController.m
pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selected= [arr objectAtIndex:indexPath.row];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.selectedText = selected;
[self.navigationController popViewControllerAnimated:YES];
}
In this way you are storing selected value in Singleton class.(App delegate). You can fetch data from this in ViewController(viewWillAppear).
I am trying to copy the array from tableview controller to view controller. I have checked the code multiple times and it seems to be okay.
//Delegate class
#import <UIKit/UIKit.h>
#protocol Category <NSObject>
#required
-(void) delegateMethodForCategory : (NSMutableArray *) arrayOfCategory;
#end
#interface Categories : UIViewController <UITableViewDelegate,UITableViewDataSource>
#property (nonatomic) id<Category> delegate;
#property (nonatomic,strong) NSArray *sports;
#property (strong, nonatomic) IBOutlet UITableView *tableview;
#property (nonatomic,strong) NSMutableArray *selectedIndexes;
#end
//Delegate methods
#import "Categories.h"
#interface Categories ()
{
NSMutableArray *array ;
}
#end
#implementation Categories
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_sports= [[NSArray alloc] initWithObjects: #"Baseball", #"Soccer", #"Hockey",
#"Other",nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return _sports.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
array = [[NSMutableArray alloc]init];
// Configure the cell...
cell.textLabel.text=[self.sports objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
if([tableView cellForRowAtIndexPath:indexPath].accessoryType==UITableViewCellAccessoryNone)
{ [tableView cellForRowAtIndexPath:indexPath].accessoryType=UITableViewCellAccessoryCheckmark;
[array addObject:cellText];
}else if([tableView cellForRowAtIndexPath:indexPath].accessoryType==UITableViewCellAccessoryCheckmark){
[tableView cellForRowAtIndexPath:indexPath].accessoryType=UITableViewCellAccessoryNone;
[array removeObject:cellText];
}
}
- (IBAction)doneButton:(id)sender {
[self.delegate delegateMethodForCategory:array];
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
#import <UIKit/UIKit.h>
#import "Categories.h"
#interface ActivityCreator : UIViewController <UIPopoverPresentationControllerDelegate, Category>
#property (nonatomic) Categories *requestClass;
#property (nonatomic,strong) NSMutableArray *arrayOfSports;
#end
//This class implements delegate
import "ActivityCreator.h"
#interface ActivityCreator ()
#end
#implementation ActivityCreator
- (void)viewDidLoad {
[super viewDidLoad];
[self settingUp];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
return UIModalPresentationNone;
}
-(void)settingUp{
_requestClass = [[Categories alloc]init];
self.requestClass.delegate = self;
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:#"hubabuba"]){
Categories *pop = (Categories *)segue.destinationViewController;
pop.modalPresentationStyle = UIModalPresentationPopover;
pop.popoverPresentationController.delegate = self;
}
}
-(void) delegateMethodForCategory : (NSMutableArray *) arrayOfCategory {
_arrayOfSports = arrayOfCategory;
NSLog(#"%#",_arrayOfSports);
}
Any guidance where I am doing wrong will be of great help. Have been stuck on this for a while.
The delegate method is not being called at all.
Thanks
Set the delegate of Categories class in prepareForSegue method instead of setting in settingUp method.
Write
pop.delegate = self;
In prepareForSegue method.
I have a view controller with a static cell named 'Make' I have two controllers one called "AddCarTableViewController" and "MakeTableViewController" when you click on the static cell named 'Make' it presents the make table view controller where you can select the make, then pops the view controller and am trying to store the selected value in the detailTextLabel of the static cell. here is my code for all the controllers.
The problem I'm having is once I select the make everything happens as it should I even log the selected item and it saves it after popping the view controller, but I can't figure out how to implement selected item into the detailTextLabel. Any help will be much appreciated!
"MakeTableViewController.h"
#import <UIKit/UIKit.h>
#import "AddCarTableViewController.h"
#protocol CarMakeDelegate <NSObject>
- (void)updateCarMake:(NSString *)updateMake;
#end
#interface MakeTableViewController : UITableViewController
#property (nonatomic, strong) NSArray *carMakes;
#property (nonatomic, weak) id <CarMakeDelegate> delegate;
#end
MakeTableViewController.m
#import "MakeTableViewController.h"
#interface MakeTableViewController ()
#end
#implementation MakeTableViewController {
NSIndexPath *oldIndexPath;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.carMakes = [[NSArray alloc] initWithObjects:#"Acura", #"Aston Martin", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.carMakes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.carMakes objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
oldIndexPath = indexPath;
NSString *addMake = self.carMakes[indexPath.row];
[self.delegate updateCarMake:addMake];
NSLog(#"%#", addMake );
[[self navigationController] popViewControllerAnimated:YES];
}
#end
AddCarTableViewController.h
#import <UIKit/UIKit.h>
#import "MakeTableViewController.h"
#interface AddCarTableViewController : UITableViewController
#property (strong, nonatomic) NSString *makeName;
#property (weak, nonatomic) IBOutlet UITableViewCell *makeCell;
#end
AddCarTableViewController.m
#import "AddCarTableViewController.h"
#interface AddCarTableViewController ()
#end
#implementation AddCarTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 4;
}
-(void)updateCarMake:(NSString *)updateMake {
self.makeCell.detailTextLabel.text = updateMake;
}
#end
You don't need to use delegate in this case. Just update the underlying data model. and call
[tableview reloadData];
When the makeViewController is popped.
In the AddCarVC's cellForRowAtIndex, add another line to check if current indexPath corresponds to Make cell and if it does update the detailLabel text.
I am building a simple app with a custom bar tab which loads the content of the ViewController from a UITableView located in another ViewController.
However, every time I try to scroll on the tableview, I get an exc_bad_access error. I enabled NSzombies and guard malloc to get more info on the issue.
In the console I get:
"message sent to deallocated instance 0x19182f20"
and after profiling I get:
# Address Category Event Type RefCt Timestamp Size Responsible Library Responsible Caller
56 0x19182f20 FirstTabBarViewController Zombie -1 00:16.613.309 0 UIKit -[UIScrollView(UIScrollViewInternal) _scrollViewWillBeginDragging]
Here is a bit of the code of the ViewController in which the error occurs:
.h file:
#import <UIKit/UIKit.h>
#import "DataController.h"
#interface FirstTabBarViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView* tabBarTable;
}
#property (strong, nonatomic) IBOutlet UIView *mainView;
#property (strong, nonatomic) IBOutlet UITableView *tabBarTable;
#property (nonatomic, strong) DataController *messageDataController;
#end
.m file:
#import "FirstTabBarViewController.h"
#import "DataController.h"
#interface FirstTabBarViewController ()
#end
#implementation FirstTabBarViewController
#synthesize tabBarTable=_tabBarTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)awakeFromNib
{
[super awakeFromNib];
self.messageDataController=[[DataController alloc] init];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.messageDataController countOfList];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"mainCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
};
NSString *expenseAtIndex = [self.messageDataController
objectInListAtIndex:indexPath.row];
[[cell textLabel] setText:expenseAtIndex];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
#end
This FirstTabBarViewController is loaded in the MainViewController with the following custom segue:
#import "customTabBarSegue.h"
#import "MainViewController.h"
#implementation customTabBarSegue
-(void) perform {
MainViewController *src= (MainViewController *) [self sourceViewController];
UIViewController *dst=(UIViewController *)[self destinationViewController];
for (UIView *view in src.placeholderView.subviews){
[view removeFromSuperview];
}
src.currentViewController =dst;
[src.placeholderView addSubview:dst.view];
}
#end
The Datacontroller class is just a simple NSMutableArray containing strings.
I am using ARC so I don't understand where the memory management error comes from. Does anybody have a clue?
Any help much appreciated ;)
Thanks!!
Ok... Thank you for the code sample...
See UIStoryboardSegue documentation, when you implement perform in your customTabBarSegue, you're responsible for setting, in the end, the correct relationship between your 2 viewControllers.
You have 2 possibilities:
setting dst as a modal child (then src is presentingViewController of dst), adding this code at the end of perform: [src presentViewController:dst animated:NO completion:nil];
setting dst as a child viewController of src - adding this code : [src addChildViewController:dst];
at the end of perform, but then, you have to remove it somewhere, or remove other childs in the same method....
Here's an implementation
#implementation customTabBarSegue
-(void) perform {
MainViewController *src= (MainViewController *) [self sourceViewController];
UIViewController *dst=(UIViewController *)[self destinationViewController];
for (UIView *view in src.placeholderView.subviews){
[view removeFromSuperview];
}
src.currentViewController =dst;
[src.placeholderView addSubview:dst.view];
// this container only show 1 viewController at a time, so we can remove previous ones
for (UIViewController *vc in src.childViewControllers) {
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
}
//then add the new View controller as child
[src addChildViewController:dst];
}
#end
Anyway, you should definitively look more into UIViewController containment...
I have two view controllers in tab bar controller. ViewControllerA has two buttons (MybuttonA and MybuttonB with enabled box unchecked in storyboard). ViewControllerB is a TableViewController. I would like to enable buttons in ViewControllerA upon selecting specific rows in ViewControllerB table.
Greatly appreciate any help...
ViewControllerA.h
#import <UIKit/UIKit.h>
#interface ViewControllerA : UIViewController {
IBOutlet UIButton * MybuttonA;
IBOutlet UIButton * MybuttonB;
}
-(IBAction)mybuttonaction:(id)sender;
#property(strong,nonatomic)UIButton *MybuttonA;
#property(strong,nonatomic)UIButton *MybuttonB;
#end
ViewControllerA.m
#import "ViewControllerA.h"
#interface ViewControllerA ()
#end
#implementation ViewControllerA
#synthesize MybuttonA;
#synthesize MybuttonB;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(IBAction)mybuttonaction:(id)sender{
NSString * link = #"https://google.com";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:link]];
}
ViewControllerB.h
#import <UIKit/UIKit.h>
#import "ViewControllerA.h"
#interface ViewControllerB : UITableViewController{
ViewControllerA *viewcontrollerA;
}
#property (nonatomic, retain) ViewControllerA *viewcontrollerA;
#end
ViewControllerB.m
#import "ViewControllerB.h"
#import "ViewControllerA.h"
#interface ViewControllerB () {
}
#end
#implementation ViewControllerB
#synthesize viewcontrollerA;
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"CONTENTS";
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(reload) forControlEvents:UIControlEventValueChanged];
[self reload];
[self.refreshControl beginRefreshing];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
{return 5;}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat: #"Cell #%d", indexPath.row];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
NSString* value = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
if ([value isEqual:#"1"]){
viewcontrollerA.MybuttonA.enabled=YES;
}
else if ([value isEqual:#"2"])
{
viewcontrollerA.MybuttonB.enabled=YES;
}
}
else {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
}
#end
In ViewControllerB, add the following line to viewDidLoad:
viewControllerA = [self.tabBarController.viewControllers objectAtIndex:0];
Then, the rest of your code should work as you have it.
Note that you should generally use self.viewControllerA instead of accessing the iVar directly unless you have a good reason for it. :-)