How to pass data from parent view to child upon opening? - ios

I want to load data (an array of strings) from the parent view into a set of UITextFields in the child view upon presenting the modalView.
I know how to pass from child to parent, and I'm sure it's even easier to go the other way, but I don't know how.
UPDATE: Update removed because I found the problem (double releasing of modal view)

Override the init method for the child view controller.
- (id) initWithStrings:(NSArray *)string {
if (self = [super init]) {
// Do stuff....
}
return self;
}
Then in the parent:
MyChildViewController *vc = [[[MyChildViewController alloc] initWithStrings: strings] autorelease];

Two ways you could do it:
1.Override the init method as Matt suggests
2.Create fields in your child class and pass those values to your text field.
#interface ChildViewController : UIViewController{
NSArray *strings;
UITextfield *textField1;
UITextfield *textField2;
}
...
- (void)viewDidLoad {
[super viewDidLoad];
textField1.text = [strings objectAtIndex:0];
textField2.text = [strings objectAtIndex:1];
}
Then in the parent class:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ChildViewController *childController = [[ChildViewController alloc] init];
childController.strings = your_array_of_strings;
[self.navigationController pushViewController:childController animated:YES];
[childController release];
}

- (id)initWithDataObject:(YourDataObjectClass *)dataObject {
if (self = [super init]) {
self.dataObject = dataObject;
// now you can do stuff like: self.myString = self.dataObject.someString;
// you could do stuff like that here or if it is related to view-stuff in viewDidLoad
}
return self;
}

If you want to get really fancy, you can make a delegate for your child view.
#protocol MyChildViewDelegate
- (NSArray*)getStringsForMyChildView:(MyChildView*)childView;
#end
#interface MyChildView : UIView
{
id <MyChildViewDelegate> delegate;
...
}
#property (nonatomic, assign) id <MyChildViewDelegate> delegate;
...
#end
Then somewhere in your view you would ask for the strings:
- (void)viewDidLoad
{
...
NSArray* strings = [delegate getStringsForMyChildView:self];
...
}
Then in your controller (or where ever) you can do:
myChildView = [[MyChildView alloc] initWith....];
myChildView.delegate = self;
...
- (NSArray*)getStringsForMyChildView:(MyChildView*)childView
{
return [NSArray arrayWithObjects:#"one", #"two", #"three", nil];
}
It's probably a little overkill in this case, but this is how UITableViews do it too: they have a data source delegate to provide them with their contents.

Related

Why is my delegate not passing data back after selecting row and dismissing view?

I have a textfield on my MainViewController that I'd like to pass a string into from my TableViewController. Specifically when I select a cell (didSelectRowatIndexPath) I'd like to take the text for that indexpath.row and dismiss the TableViewController passing the string into the textfield on my MainViewController. I have attempted to create a delegate to get this to work but all it says in the debugging window is that the correct string is passing but never appears in the textfield... Here is my code showing everything necessary for the delegation.
My TableViewController.h where the delegate is declared...
#protocol sendDataProtocol <NSObject>
- (void)sendDataToMain:(NSString*)text;
#end
#interface TableViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource> {
__weak id selectDataDelegate;
}
#property(nonatomic,weak)id<sendDataProtocol> selectedDataDelegate;
#property(strong,nonatomic)NSArray *presetList; //Holds the strings I want to pass
#end
Then my TableViewController.m file...
#interface TableViewController ()
#end
#implementation TableViewController
#synthesize selectedDataDelegate;
-(void)viewDidLoad {
//http://morsecode.scphillips.com/morse.html
self.presetList = [NSArray arrayWithObjects:#"AS",
#"BCNU",
#"CL",
#"CT",
#"CUL",
#"K",
#"QSL",
#"QSL?",
#"QRX?",
#"QRV",
#"QRV?",
#"QTH",
#"QTH?",
#"R",
#"SN",
#"SOS",
#"73",
#"88",
nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.selectedDataDelegate sendDataToMain:self.presetList[indexPath.row]];
NSLog(#"Delegate says: %#", self.presetList[indexPath.row]);
//The NSLog does display the correct cell I pressed, but no data passes back
[self dismissViewControllerAnimated:YES completion:nil];
}
Now here is my MainViewController.h file, this is where my textfield resides, and how I implement the delegate into this file...
#interface MainViewController : UIViewController<UITextFieldDelegate, CAAnimationDelegate, sendDataProtocol> //include protocol here
#property(strong,nonatomic)UITextField *morseTextfield;
- (void)sendDataToMain:(NSString*)text; //conform to protocol
#end
Now the MainViewController.m file...
- (void)viewDidLoad {
[super viewDidLoad];
TableViewController *tvc = [TableViewController new];
tvc.selectedDataDelegate = self;
}
//Protocol method declared here
- (void)sendDataToMain:(NSString*)text {
NSString *str = text;
self.morseTextfield.text = str;
NSLog(#"text: %#",text);
}
The textField NSLog never displays anything, so its not connecting to the delegate or something.
So something is clearly wrong but I'm not sure what. I used this stackoverflow answer as a reference but even then couldn't get it to work (refer to the passing data back section)
Passing Data between View Controllers
Also as a side note I'm coding everything programmatically. Any help is appreciated, thank you.
This is how i created the textfield...
//CONFORMING TO DELEGATES
self.morseTextfield.delegate = self;
//CREATING AND ADDING TEXTFIELD TO VIEW
self.morseTextfield = [[UITextField alloc]initWithFrame:CGRectMake((self.view.frame.size.width-300)/2,
(self.view.frame.size.height)/7, 300, 30.0)];
self.morseTextfield.borderStyle = UITextBorderStyleRoundedRect;
self.morseTextfield.font = [UIFont fontWithName:#"Avenir Next" size:20];
self.morseTextfield.textAlignment = NSTextAlignmentCenter;
self.morseTextfield.placeholder = #"Translate text into morse code";
[self.morseTextfield addTarget:self action:#selector(dismissKeyboard) forControlEvents:UIControlEventEditingDidEndOnExit];
self.morseTextfield.autocorrectionType = UITextAutocorrectionTypeNo;
self.morseTextfield.spellCheckingType = UITextSpellCheckingTypeNo;
self.morseTextfield.autocapitalizationType = UITextAutocapitalizationTypeNone;
[self.morseTextfield setReturnKeyType:UIReturnKeyDone];
[self.view addSubview:self.morseTextfield];
Possibly you set delegate to one instance of TableViewController and display another one.
- (void)viewDidLoad {
[super viewDidLoad];
TableViewController *tvc = [TableViewController new];
tvc.selectedDataDelegate = self;
}
in your code tvc will be just released from memory and you delegate will not work.
Also in you .h file this row is useless.
- (void)sendDataToMain:(NSString*)text; //conform to protocol
In your MainViewController update next method. You have to set delegate in it
- (void) tableViewBtnPressed:(UIBarButtonItem *)sender {
MCTableViewController *tableVC = [[MCTableViewController alloc] init];
tableVC.selectedDataDelegate = self;
UINavigationController *navBar = [[UINavigationController alloc]initWithRootViewController:tableVC];
[self.navigationController presentViewController:navBar animated:YES completion:nil];
}

How to keep objects in NSMutableArray?

There are two view controllers.One to add items,the other one to display(table view).All items are stored in an NSMutableArray.But every time I unwind to add item and when I go back to the table view, there is only the newest item left.
Code:
- (void)viewDidLoad {
[super viewDidLoad];
[self addData];
}
- (void)addData {
if (!self.items) {
self.items = [[NSMutableArray alloc] init];
}
[self.items addObject:self.textFromFirst];
}
// textFormFirst is an NSString which received from the previous view controller
add view controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UINavigationController *nav = [segue destinationViewController];
SecondController *second = [nav.viewControllers objectAtIndex:0];
second.textFromFirst = [self getText]; // get inputed string
self.aTextField.text = #"";
}
You can share an NSMutableArray between your two view controllers. Just use a property:
MainViewController:
// .m
#interface MasterViewController ()
#property (nonatomic, strong) NSMutableArray *items;
#end
#implementation MasterViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.items = [NSMutableArray array];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"ShowDetail"]) {
DetailViewController *controller = (DetailViewController *)[segue destinationViewController];
controller.items = self.items;
controller.textFromFirst = #"This is a test";
}
}
#end
AddViewController:
// .h
#interface DetailViewController : UIViewController
#property (nonatomic, copy) NSString *textFromFirst;
#property (nonatomic, strong) NSMutableArray *items;
#end
// .m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addData];
}
- (void)addData {
[self.items addObject:self.textFromFirst];
}
These is a sample project: https://www.dropbox.com/s/ymum4zivgi0z688/TestUnwindSegue.zip?dl=0
I do not know why are you using array in AddViewController. Maybe you are prefer use unwind segue, like so:
// MainViewController.m
- (IBAction)saveItem:(UIStoryboardSegue *)segue {
DetailViewController *detailVC = segue.sourceViewController;
[self.items addObject:detailVC.textFromFirst];
}
In the case, you don't need to share an NSMutableArray to AddViewController.
How are you persisting the NSMutableArray between view controllers? If you need to persist one array across your entire application I would suggest you use a singleton. A singleton is an object that each instance has only 1 memory address, thus is always the same object. You could accomplish this by doing the following:
1) Press CMD+N and select "Cocoa Touch Class" / subclass NSMutableArray
2) Go to that class' .m file and add the singleton in init
static YourNSMutableArray *highlander;
#implementation YourNSMutableArray
- (instancetype)init {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
highlander = [super init];
});
return highlander;
}
3) Now whenever you create a new instance in any of your view controllers like this
if (!self.items) {
self.items = [YourNSMutableArray new];
}
[self.items addObject:self.textFromFirst];
self.items will always have the stored self.textFromFirst because any YourNSMutableArray you create in your app will always be the same object.

Reloading table data from another class in iOS

As will be seen from my question, I'm a beginner to iOS development. I have looked at several tutorials and several questions but none seem to be covering my case (I'm probably missing something). I am simply trying to add elements to an array from one class, then call the method that reloads the table data from another class. However, when I try to reload the data after calling the relevant method from another class, the table fails to be loaded (no new data seems to be added). In fact, even the previous values of the array in the table seem to be gone.
Class A:
MyClassA.h
#interface MyClassA : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
UITableView *tableView;
NSMutableArray *Elements;
}
#property UITableView *tableView;
#property NSMutableArray *Elements;
-(void) addElement: (NSString *) ElementName;
#end
MyClassA.m
#implementation MyClassA
{
NSString *ElementName[10];
}
- (void) viewWillAppear:(BOOL)animated
{
NSLog(#"MyClassA: viewWillAppear");
ElementName[0] = #" 1 ";
ElementName[1] = #" 2 ";
ElementName[2] = #" 3 ";
Elements = [[NSMutableArray alloc]initWithObjects:ElementName[0], ElementName[1], ElementName[2],nil];
self.tableView.dataSource = self; // The table successfully loads with the data element
}
-(void) addElement: (NSString *) ElementName
{
NSLog(#"Entered addElement"); // This method is successfully accessed
Elements = [[NSMutableArray alloc]initWithObjects:ElementName[0], ElementName[1], ElementName[2],nil]; // The problem is here, printing data in this array shows they have no value
[self.tableView reloadData]; // The problem is here. This does not load the data
}
Class B:
MyClassB.h
#class MyClassA
#interface MyClassB : UIViewController
#property (nonatomic, strong) MyClassA *MyClassACall
-(IBAction) MyButtonClicked: (id) sender;
#end
MyClassB.m
#implementation MyClassB
#synthesize MyClassACall;
-(id) init
{
self = [super init]
if (self) {
NSLog(#"MyClassB init");
MyClassACall = [[MyClassA alloc] init];
}
return self;
}
-(IBAction)MyButtonClicked:(id)sender
{
NSLog("My button is clicked");
[self.MyClassAcall addElement:#"NewElement"];
}
I successfully get all the NSlogs, and the table loads the first time correctly with the provided data. However, when trying to add data by loading a method from another class, the table data remains the same and does not get reloaded. What am I missing here?
I have not loaded the whole code to keep this simple. I hope that this makes sense and please let me know if I could clarify. If a similar question exists, please point me to it and I appreciate your help.
I've made a mini tutorial here for you.
OK, so let's say we got a scenario like this:
There are two view controllers - ViewControllerA and ViewControllerB.
ViewControllerA will be in charge of adding items.
ViewControllerB will be in charge of displaying the items.
So ViewControllerA will look like this:
and ViewControllerB will look like this:
ViewControllerA.h
#import <UIKit/UIKit.h>
#interface ViewControllerA : UIViewController
#property (nonatomic, strong) NSMutableArray *arrItems;
#end
Here, we store the data source called arrItems as a NSMutableArray. We will pass this array to ViewControllerB later.
ViewControllerA.m
#import "ViewControllerA.h"
#import "ViewControllerB.h"
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initViews];
}
-(void)initViews
{
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = #"View Controller A";
UIButton *btnAddItem = [[UIButton alloc] initWithFrame:CGRectMake(60, 200, 200, 50)];
[btnAddItem setTitle:#"Add Item" forState:UIControlStateNormal];
btnAddItem.backgroundColor = [UIColor greenColor];
btnAddItem.layer.cornerRadius = 5.0;
[btnAddItem addTarget:self action:#selector(addItem) forControlEvents:UIControlEventTouchUpInside];
UIButton *btnViewData = [[UIButton alloc] initWithFrame:CGRectMake(60, 300, 200, 50)];
[btnViewData setTitle:#"View Data" forState:UIControlStateNormal];
btnViewData.backgroundColor = [UIColor blueColor];
btnViewData.layer.cornerRadius = 5.0;
[btnViewData addTarget:self action:#selector(viewData) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnAddItem];
[self.view addSubview:btnViewData];
// init empty array to hold data source items
self.arrItems = [[NSMutableArray alloc] init];
}
-(void)addItem
{
[self.arrItems addObject:#"New Element"];
NSLog(#"added a new element to arrItems, arrItems now has %u items", self.arrItems.count);
}
-(void)viewData
{
ViewControllerB *vcB = [[ViewControllerB alloc] initWithItems:self.arrItems];
[self.navigationController pushViewController:vcB animated:YES];
}
For the green "Add Item" button, we use a method like this to add item to our data source:
-(void)addItem
{
[self.arrItems addObject:#"New Element"];
NSLog(#"added a new element to arrItems, arrItems now has %u items", self.arrItems.count);
}
You'll notice when you tap on the green button, you'll get a console log telling you how many items is currently in your array.
Now when we're done adding items, we have the blue "View Data" button which pushes ViewControllerB onto the navigation stack:
-(void)viewData
{
ViewControllerB *vcB = [[ViewControllerB alloc] initWithItems:self.arrItems];
[self.navigationController pushViewController:vcB animated:YES];
}
ViewControllerB.h
#import <UIKit/UIKit.h>
#interface ViewControllerB : UIViewController <UITableViewDataSource, UITableViewDelegate>
-(id)initWithItems:(NSArray *)arrItems;
// ----------------------------------------------------------------
// view controller B data source is set from
// view controller A using init method shown above
// ----------------------------------------------------------------
#property (nonatomic, copy) NSArray *arrItems;
#property (nonatomic, strong) UITableView *tableView;
#end
Here, we've declared a init method that takes a NSArray parameter. This method will allow us to inject the data source array from ViewControllerA into ViewControllerB.
Per the usual, we also have the tableView in ViewControllerB.
ViewControllerB.m
-(id)initWithItems:(NSArray *)arrItems
{
self = [super init];
if(self)
{
self.arrItems = arrItems;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initViews];
}
-(void)initViews
{
self.navigationItem.title = #"View Controller B";
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.arrItems.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.textLabel.text = self.arrItems[indexPath.row];
return cell;
}
Notice in the initWithItems: method, we're storing the data source from the passed in parameter arrItems into ViewControllerB's self.arrItems:
-(id)initWithItems:(NSArray *)arrItems
{
self = [super init];
if(self)
{
self.arrItems = arrItems;
}
return self;
}
ViewControllerB can then use this data and display it in the tableView data source methods.
So you end up with something like this if you click Add Item five times:
Xcode's console also logs 5 items added:
2014-12-08 10:33:39.195 DataPassingDemo[1211:25705] added a new element to arrItems, arrItems now has 1 items
2014-12-08 10:33:40.099 DataPassingDemo[1211:25705] added a new element to arrItems, arrItems now has 2 items
2014-12-08 10:33:40.619 DataPassingDemo[1211:25705] added a new element to arrItems, arrItems now has 3 items
2014-12-08 10:33:41.123 DataPassingDemo[1211:25705] added a new element to arrItems, arrItems now has 4 items
2014-12-08 10:33:41.667 DataPassingDemo[1211:25705] added a new element to arrItems, arrItems now has 5 items
Is that more clear ?
First of all, i think, it's eligible way to make array in C way as elementName[10], but at this way it's overflow, you can simply use objective-c style with literals, or "initWithCapacity:10". Also Simplify your code, change it at this way:
#implementation MyClassA
{
//NSString *ElementName[10]; // you already have NSMutableArray, why did you do this ?
}
- (void) viewWillAppear:(BOOL)animated
{
NSLog(#"MyClassA: viewWillAppear");
Elements = [#[#"1",#"2",#"3"] mutableCopy];
self.tableView.dataSource = self;
}
-(void) addElement: (NSString *) ElementName
{
NSLog(#"Entered addElement"); // This method is successfully accessed
// You already have initialized array, you need simply to add new element
[elements addObject: elementName];
[self.tableView reloadData];
}
Okay, so. Couple of things...
The way you defined your Elements array is an old method of doing things, You do not need to declare the ivar just the property.
MyClassACall = [[MyClassA alloc] init]; is creating a new instance of MyClassA so whatever you set on that will not actually appear on your view controller you had.
If you need to display a model on one view controller and update it in another view controller i would recommend centralising that model so that both view controllers can access/mutate this model. Singleton is probably the easiest way to achieve that.

Add Item from another class to a property from another class. Objective-C

So I have two classes. When press the save button, it will pass down the value from self.screen.text by addItem method to the totalArray in class 2. If I try to NSLog in the #implementation of addItem method, then it will give out the correct output but If I do it in viewDidLoad, the output is null. How can I save the value passing from class1 to property of class2 permanently? Thank you. The class2 in a subclass of UITableViewController
Class 1 #interface
//class1.h
#import class2.h
#interface class1 : superclass {
}
- (IBAction)buttonSave:(id)sender;
Class1 #implementation
//class1.m
#interface class1 ()
#end
#implementation class1 {
}
- (IBAction)buttonSave:(id)sender {
class2 *Obj = [[class2 alloc] init];
[Obj addItem:self.screen.text];
}
And class2 #interface
//class2.h
#import class2.h
#interface {
}
#property (strong, nonatomic) NSMutableArray *totalArray;
class2 #implementation
#interface class2 ()
#end
#implementation {
}
- (void) addItem:(id)item {
self.totalArray = [[NSMutableArray alloc] init]; //alloc & init
[self.totalArray addObject:item]; //add object to the total array
// NSLog(#"%#", self.totalArray); If I NSLog in within this method then everything works as expected.
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"%#", self.totalArray); //But in here the output is null. ???
}
I think that your problem is that you have use a different class2 object. The one that you had init in buttonSave, is not the one that you are displaying
add a property in class1.h
#property (nonatomic, strong) NSMutableArray *savedArray;
and modify buttonSave :
- (IBAction)buttonSave:(id)sender {
self.savedArray = [[NSMutableArray alloc] init];
[self.savedArray addObject:self.screen.text];
}
You are using a storyboard, then please try to add this in class1.h and add an identifier class2Segue to this segue in your storyboard :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"class2Segue"])
{
Class2 *tableController = (Class2 *)[segue destinationViewController];
tableController.totalArray = self.savedArray;
}
}
viewDidLoad is called after init so you array is nil here. Change your class2 init method to accept the item.
// In class2
-(id) initWithStyle:(UITableViewStyle)style andItem:(id)item {
self = [super initWithStyle:style];
if(self) {
self.totalArray = [[NSMutableArray alloc] init];
[self.totalArray addObject:item];
}
return self;
}
Your addItem will then look like,
- (void) addItem:(id)item {
//Just add, do not initialize again
[self.totalArray addObject:item];
}
The button action in class1 will now look like,
- (IBAction)buttonSave:(id)sender {
class2 *Obj = [[class2 alloc] initWithItem:self.screen.text];
//OR
//class2 *Obj = [[class2 alloc] initWithItem:UITableViewStylePlain andItem:self.screen.text];
}
Hope that helps!
Try to use like this...
- (IBAction)buttonSave:(id)sender
{
class2 *Obj = [[class2 alloc] init];
Obj.totalArray = [[NSMutableArray alloc] init]; //alloc & init
[Obj.totalArray addObject:self.screen.text];
NSLog(#"screen.text %#", self.screen.text); // -- check here it may be null----
NSLog(#"Obj.totalArray %#", Obj.totalArray);
}
#interface class2 ()
#end
#implementation {
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"%#", self.totalArray); //But in here the output is null. ???
}
You can not ensure when your viewDidLoad method will call... so better pass the value to the init method and set there initWithText:(NSString*)text{}. Other wise try to call NSLog in viewWillAppear or viewDidAppear just for testing purpose. In iOS 7 now presentation of view-controllers is bit changed now.

didSelectItemAtIndexPath pushViewController

I'm trying to accomplish something incredibly simple. I am trying to programmatically push to a viewController when the only item in my collection view is pushed. Nothing happens. I believe there is more than one problem in my tangled mess. My understanding of the basics of arrays is clearly anything but. If I put an NSLog line inside my if statement below, I get nothing when pushing my lone item. Here is my didSelectItemAtIndexPath method:
NSMutableArray *itemApp = [model.viewControllers objectAtIndex:indexPath.row];
if (itemApp == 0) {
NSLog (#"This does not appear")
TableViewController *ctc = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:ctc animated:YES];
}
model is defined in viewDidLoad:
model = [[SimpleModel alloc] init];
SimpleModel is mentioned in the .m implementation:
#implementation smileController;
{
SimpleModel *model;
}
viewControllers is property of the SimpleModel class, along with its friend, apps:
#property (nonatomic, strong) NSMutableArray *apps;
#property (nonatomic, strong) NSMutableArray *viewControllers;
Here is the SimpleModel.m
- (id)init
{
if (self = [super init])
{
self.apps = [NSMutableArray arrayWithObjects:#"1", nil];
self.viewControllers = [NSMutableArray arrayWithCapacity:self.apps.count];
TableViewController *tvc = [[TableViewController alloc] init];
[self.viewControllers addObject:tvc];
}
return self;
}
In SimpleModel.m you populate the viewControllers array with a single TableViewController.
Given this, when the first block of code you posted should be more like this:
TableViewController *itemApp = [model.viewControllers objectAtIndex:indexPath.row];
if (itemApp) {
NSLog (#"This should appear")
[self.navigationController pushViewController:itemApp animated:YES];
}
This assumes you want to push the view controller you obtain from the model.viewControllers property.
Please note that itemApp can only be nil if model or model.viewControllers are nil.

Resources