passing an NSMutableArray to an other View - uitableview

my problem is this I fill my Array in my rootView and want to pass this Array to the mainView View.
I tryed it this way:
mvController = [[mainViewController alloc] initWithNibName:#"mainViewController" bundle:[NSBundle mainBundle]];
mvController.listOfContent == self.listOfContent;
[self.navigationController pushViewController:mvController animated:YES];
mvController = nil;
[mvController release];
did I missed some thing?

In theory, it's correct, except because of the "release", that must be before "mvController = nil" (otherwise, you will be releasing "nil").
You must be more specific with your error, but probably the mistake regards using "listOfContent" inside viewDidLoad or init.

Related

How can i refresh view when i use removefromsuperview method?

I have two view controllers on iOS app.
The first view controller (A), store a table view with cells of data.
When i select a cell, i use the follow method for go to second view controller (B):
if (secondViewController == nil) {
secondViewController = [[SecondViewController alloc] initWithNibName: #"nibName" bundle:nil];
}
[self.view addSubview:secondViewController.view];
When i am in the second view controller (B) and i want come back to first view controller (A) i use the method:
[self.view removeFromSuperview];
And then i come back to first view controller (A).
The problem is:
When i select a different cell in the first view controller (A) i go to the second view controller (B) but this time, with the same data of the previous cell.
The view controller doesnt refresh data automatically...
I tried use the viewWillAppear, but it didnt work so i need a bit help. By the other hand, viewDidAppear doesnt work too of course.
Thanks to all.
The reason it's like that is because you create secondViewController just first time (lazy loading) after that you just add subview:
if (secondViewController == nil) {
secondViewController = [[SecondViewController alloc] initWithNibName: #"nibName" bundle:nil];
}
You can sort it out by doing:
secondViewController = [[SecondViewController alloc] initWithNibName: #"nibName" bundle:nil];
[self.view addSubview:secondViewController.view];
But where do you load the data to your subview. If you want to change the view depending on data you should do something like that:
if (secondViewController == nil) {
secondViewController = [[SecondViewController alloc] initWithNibName: #"nibName" bundle:nil];
}
//Pass some data here
secondViewController.SOMEDATA = YOURDATA;
[self.view addSubview:secondViewController.view];
[viewThatYouWantToRefresh setNeedsDisplay];
or if you need to update the data in the cells on the UITableView:
[tableView reloadData];
I am sure I understood you correctly but I think you can change
if (secondViewController == nil) {
secondViewController = [[SecondViewController alloc] initWithNibName: #"nibName" bundle:nil];
}
to
secondViewController = [[SecondViewController alloc] initWithNibName: #"nibName" bundle:nil];
So you will recreate SecondViewController each time you choose new cell.
Just remove this condition:
if (secondViewController == nil)
i.e no need to check if secondViewController is nil or not. The problem is you are creating secondViewController only once.

Custom Init Method not working

I'm trying to populate UITextFields inside a UITableViewController with a click of a cell. So, I created an init method like:
- (id)initWithObjetoFormulario:(ObjetoFormularioGerenciador *)umObjeto
{
self = [super init];
if(self){
self.objetoFormulario = umObjeto;
}
return self;
}
In my ViewDidLoad I put the line if(self.objetoFormulario){ and after that link the UITextFields to my Object. I don't think there's anything wrong at this point.
So, my Second TableViewController is a SearchDisplayController, it finds the Data I need and at didSelectRowAtIndexPath I have:
ObjetoFormularioGerenciador *objeto = [[ObjetoFormularioGerenciador alloc] init];
[objeto RecebeArrayComDadosECriaObjetoFormularioGerenciador:_arrayComDados eEmail: [searchResults objectAtIndex:indexPath.row]];
GerenciarSeriesTableViewController *gerenciador = [[GerenciarSeriesTableViewController alloc] initWithObjetoFormulario:objeto];
[self.navigationController pushViewController:gerenciador animated:NO];
As I don't have the actual objects in my cells, I call a method to retrieve the object according to the cell entry, that is working as well, now, it opens a blank TableView when I click the cell. It should go Back to my tableView with static Cells containing UITextFields and populate them.
When I use this code:
ObjetoFormularioGerenciador *objeto = [[ObjetoFormularioGerenciador alloc] init];
[objeto RecebeArrayComDadosECriaObjetoFormularioGerenciador:_arrayComDados eEmail:[searchResults objectAtIndex:indexPath.row]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
GerenciarSeriesTableViewController *gerenciador = [sb instantiateViewControllerWithIdentifier:#"GerenciarSeriesTableViewController"];
[self.navigationController pushViewController:gerenciador animated:NO];
It does open the TableView I want, but it doesn't populate the UITextFields as I didn't pass any object.
Thanks.
Yes, you really don't generally have custom init methods for view controllers, but rather rely upon the standard ones, and then once the view controller has been instantiated, you'd just set the property then, e.g.:
ObjetoFormularioGerenciador *objeto = ... // create and configure objeto
GerenciarSeriesTableViewController *gerenciador = [self.storyboard instantiateViewControllerWithIdentifier:#"GerenciarSeriesTableViewController"];
gerenciador.objetoFormulario = objeto;
[self.navigationController pushViewController:gerenciador animated:NO];
You can also have a segue between the two view controllers, give it an identifier, and then call [self performSegueWithIdentifier:...], and then set the objetoFormulario in the prepareForSegue method. But the above technique should work fine, too.

Popover is shown null

I'm trying to show a popover with a title, creating a root view controller and instantiating it with my viewController. But, when I show the popover, the content is not shown. Here is the code:
UIViewController *popContentViewController = [[sb instantiateViewControllerWithIdentifier:#"videosTutoriais"] init];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:popContentViewController];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
_popover.delegate = self;
[popContentViewController release];
[controller release];
//dados.myPopoverController = popOverController;
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Just to be more specific, the title of popover appears normally, but the content doesn't.
Just double check that popContentViewController is not nil. You have the identifier #"videosTutoriais" which looks like it might be a scanning error.
From your code, you are releasing the controller before you display in on the screen. Try releasing it after or in the dealloc method. If you are unsure about memory management. I suggest you try ARC instead to avoid silly errors and mistakes such as this.
The code looked like this:
sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
UINavigationController *controller = [[sb instantiateViewControllerWithIdentifier:#"navTutorial"] init];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[controller release];

UINavigationController shows but without back button

In my delegate class I have this -
BluenibViewController *mvc = [[BluenibViewController alloc] init];
UINavigationController *unvc = [[UINavigationController alloc] init];
[unvc pushViewController:mvc animated:NO];
[mvc release];
[self.window addSubview:unvc.view];
[self.window makeKeyAndVisible];
return YES;
and in my BluenibViewController I have this method -
-(IBAction) BookingsViewController:(id)sender
{
bookingsViewController1 = [[BookingsViewController alloc]
initWithNibName:#"BookingsViewController"
bundle:nil];
UINavigationController *navController = self.navigationController;
[navController pushViewController:bookingsViewController1 animated:YES];
self.title = #"Bookings";
[self.window makeKeyAndVisible];
[self.view addSubview:bookingsViewController1.view];
[navController release];
[bookingsViewController1 release];
}
Ob click of this method I am able to go to the next view but there is no back button on the navigation bar.
Please point me to the silly mistake I am doing.
I see quite a few errors here. Lets see if I can't be of some service.
First, I see that you're overreleasing your navigation controller [navController release];
Second, you should only have to make the window key/visible once in your entire project. You set your navController as the rootViewController for your window, make it key/visible, and then you should never have to do anything with your window again. Don't think it's breaking anything, but you should remove all calls to make key/visible beyond the first.
In the end, pushing a new view controller should look like this:
[self.navigationController pushViewController:[[[BookingsViewController alloc] init] autorelease] animated:YES];
You shouldn't need anything else to get what you're looking for.
You should not add unvc.view as a subview of self.window. You should just assign unvc as self.window.rootViewController:
self.window.rootViewController = unvc;
and you should not add bookingsViewController1.view as a subview of self.view (in your BookingsViewController: method). The navigation controller will take care of getting bookingsViewController1.view onto the screen after you have pushed it.
self.navigationItem.hidesBackButton =YES;
Follow this code . Hope it helps ....
it comes a little bit late but in iOS 8 you can do:
[self.navigationController pushViewController:secondViewController animated:YES];

Inject a NSString text to another UIViewController

I'm trying to pass a NSString text to a UIViewController in button "click" event in iOS. I wrote following code.
self.detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
self.detailViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:self.detailViewController animated:YES];
self.detailViewController.urlAddress = #"http://www.google.com";
I've already declared urlAddress property in detailViewController.
After I tested with NSLog in viewWillAppear, it shows only null values, not the urlAddress string. How can I solve it?
You're setting the string after the view controller was already presented. Switch that and you should be good.
Note the order of methods being called:
initWithNibName
viewDidLoad
viewWillAppear
Your string is changed only after all three have done their work.
Change your code to:
self.detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
self.detailViewController.urlAddress = #"http://www.google.com";
self.detailViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:self.detailViewController animated:YES]; //Triggers viewWillAppear eventually

Resources