Why my add items dont save on memory? When I back to RootViewController my list disappear, What happened ?
Code for add and work fine...
- (IBAction) addButtonPressed: (id)sender {
NSLog(#"Add button pressed!");
addPosto *addposto = [[addPosto alloc] initWithNibName:#"postoDictionary" bundle:nil];
UINavigationController *addNavCon = [[UINavigationController alloc] initWithRootViewController:addposto];
addposto.postoArray = self.poscomb;
[self presentModalViewController:addNavCon animated:YES];
[addposto release];
[addNavCon release];
}
On RootViewController select row "Meus Postos"
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
postoLista *codigo = [[postoLista alloc] initWithNibName:#"postoLista" bundle:nil];
[self.navigationController pushViewController:codigo animated:YES];
[codigo release];
}
So I need to know how I archieve list on memory after add items, thanks for attention!
Eduardo Parucker.
I talk to Leonardo of Instants Games on Brazil he implement a singleton and resolved my problem, so I think thats it! thanks for all helps!
Related
I have some apps designed for iOS 6 and today I went to upgrade them to iOS 7.
They are a simple table view lists and when a record is selected it displays details about that row on another screen. This worked flawlessly in iOS 6. With iOS 7 when I select a row it shows a blank data page on the first selection. If I then go back to the list and reselect the item it then displays the proper data.. After this first blank display it will work fine for any other records..
I am racking my brain and can not for the life of me figure out why this is happening.
Any ideas?
CODE:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Statutes *statute = (Statutes *)[self.statutes objectAtIndex:indexPath.row];
if(self.detailView == nil) {
DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
self.detailView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.detailView animated:YES];
self.detailView.title = [statute myStatute];
[self.detailView.statuteFullText setText:[statute myDescription]];
[self.detailView.statuteTitle setText:[statute myTitle]];
[self.detailView.favoritesID setText:[statute myPriority]];
[self.detailView.recordID setText:[statute myRecord]];
if ([#"1" isEqualToString:[statute myPriority]]) {
[self.detailView.favoriteControl setTitle:#"Remove from favorites"];
} else {
[self.detailView.favoriteControl setTitle:#"Add to favorites"];
}
}
Also, the part that changes the button title Add to Favorites etc, does not change on the first item selection, it simply shows "Item".
Thanks.
UPDATE:
So I narrowed it down to this piece of code:
if(self.detailView == nil) {
DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
self.detailView = viewController;
[viewController release];
}
If I remove the if clause then it happens on every selection. If I comment out the whole code I cant make any selections. So I imaging I have to find another way to initialize my view controller. Any ideas? Why did this work in iOS 6 then?
NEW ANSWER: (9/25/13)
I was bothered by the backwards hack that I had to do to get this to work, plus when I called the detailView from other screens I ran into a similar problem that was not fixed by this hack so I found another easier fix..
All I had to do was surround the commands that were used to set the values on the view in question within a asynchronous tag and viola! Everything worked..
Here is my solution:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Statutes *statute = (Statutes *)[self.statutes objectAtIndex:indexPath.row];
if(self.detailView == nil) {
DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
self.detailView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.detailView animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
self.detailView.title = [statute myStatute];
[self.detailView.statuteFullText setText:[statute myDescription]];
[self.detailView.statuteTitle setText:[statute myTitle]];
[self.detailView.favoritesID setText:[statute myPriority]];
[self.detailView.recordID setText:[statute myRecord]];
if ([#"1" isEqualToString:[statute myPriority]]) {
[self.detailView.favoriteControl setTitle:#"Remove from favorites"];
} else {
[self.detailView.favoriteControl setTitle:#"Add to favorites"];
}
});
}
So now as u can see the
dispatch_async(dispatch_get_main_queue(), ^{
is around the items to be set on the view. I got rid of all of the extra crap in the -ViewDidLoad section...
perfect.
OLD ANSWER: (9/24/13)
Well, I got it to work. It is a total backwards hack but I'm results driven so I don't care. It does kind of upset me that this functionality has changed and needed this hack but whatever.. I hope this helps others who I am sure may be running into this.
I left the above code alone and in the
- (void)viewDidLoad
section I added the following code:
DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
self.detailView = viewController;
[viewController release];
[self.navigationController pushViewController:self.detailView animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[self.navigationController popToRootViewControllerAnimated:NO];
});
What this does is instantiates the DetailViewController, displays it, then pops it. When the app loads it appears to be at the main screen, as expected, and when making a selection it now works on the first time because technically it is NOT the fist time...
-LK
I have a big problem: on method didSelectRowAtIndexPath I always get null to self.navigationController. I have a UIViewController that contains a UIsegmentedControl and a subView. On this subView I add the controllers for each segment selected. For each segment a have a tableview. Here is the problem: when I select a row from this tableview I can't do push for next controller because self.navigationController is null.
Please help me..Here is my code : http://pastebin.com/qq0vf7mq
without the code :
navigationTelephone=[[UINavigationController alloc] init];
[self.view addSubview:self.navigationTelephone.view];
[self.navigationTelephone setNavigationBarHidden:YES];
[self.view addSubview:tableViewTelephone];
I think You have initialize the UINavigationController like below
[[UINavigationController alloc] initWithRootViewController:ViewControllerOBj]
Updated:
You initialize an instance variable navigationTelephone and display it, but you use self.navigationController to push!
Use [navigationTelephone push...] instead
Try this one:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
myAudiPhoneInputViewController *myViewController = [[myAudiPhoneViewController alloc] initWithNibName:#"NIB NAME HERE" bundile:nil];
self.myaudiPhoneInputViewController = myViewController;
[myViewController release];
[tableViewTelephone deselectRowAtIndexPath:indexPath animated:NO];
if(indexPath.row==0){
NSLog(#"Tel.personnel... %#",self.navigationTelephone);
[self.navigationController pushViewController:self.myaudiPhoneInputViewController animated:YES];
}
}
You haven't instantiate your myaudiPhoneViewController that is why it's not pushing the view.
Just check by changing,
self.navigationTelephone=[[UINavigationController alloc] init];
Naveen Shan
I have spent several hours on this, and tried various things. I can confirm that the didSelectRowAtIndexPath is indeed being run, and the specific object I am looking for is being returned.
The bit that isn't doing anything is the part where I am trying to display the SensDetailViewClass view. It runs the code, but the viewDidLoad method in SensDetailViewClass.m doesn't run, and the view doesn't change.
I would like to have the SensDetailViewClass displayed. I can confirm that the .xib file's owner is the SensDetailsViewClass.
Please help. Here's the code.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// get the selected item
Sens *info = [_sensInfos objectAtIndex:indexPath.row];
// initialise the detail view controller and display it
SensDetailViewClass *details = [[SensDetailViewClass alloc] initWithNibName:#"MainWindow" bundle:nil];
// set the title of the page
[details setTitle:info.heading];
details.selectedSens = info;
[self.navigationController pushViewController:details animated:YES];
[details release];
}
UPDATE: I got it to work by using this mechanism:
[self presentModalViewController:details animated:YES];
SensDetailViewClass *details = [[SensDetailViewClass alloc] initWithNibName:#"SensDetailViewClass" bundle:nil];
[self.navigationController pushViewController:details animated:YES];
i think you are fresher so nedd to check the link of tutorial
http://www.icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/
Are you sure your SensDetailViewClass class has MainWindow as its .xib file?
Please check it and replace nib name `
initWithNibName:#"MainWindow"
in above code
Thanks,
1 ) Are you sure y*ou have the navigation comptroller in the app* or its just the View Based application.
IF this is ok then ,
2)
// initialise the detail view controller and display it
SensDetailViewClass *details = [[SensDetailViewClass alloc] initWithNibName:#"You-Xib name for this View" bundle:nil];
// set the title of the page
[details setTitle:info.heading];
details.selectedSens = info;
[self.navigationController pushViewController:details animated:YES];
[details release];
http://blog.webscale.co.in/?p=244
From the above i download Calendar Test application...
i got calendar and tableview....in a same View.
Now i created another class DetailedViewController which is UIViewControllerSubClass.
Now for the selected row i need to display the detailedViewController Nib file.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSLog(#"Calling");
DetailedViewController *detailedView=[[DetailedViewController alloc] initWithNibName:#"DetailedViewController" bundle:nil];
[self.navigationController pushViewController:detailedView animated:YES];
[detailedView release];
detailedView=nil;
}
Which is not navigating to my detailedView
What to do for navigation.
#All Please help me out.
You download an View Based Application so if you want to display Detail vIew on tapping a row then change your code like
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSLog(#"Calling");
YourAppDelegateClass *obj=(YourAppDelegateClass *)[[UIApplication sharedApplication] delegate];
DetailedViewController *detailedView=[[DetailedViewController alloc] initWithNibName:#"DetailedViewController" bundle:nil];
[obj.window addSubview:detailedView];
[detailedView release];
detailedView=nil;
}
You have to make a navigation controller in AppDelagate method as,
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:calender];
[window addSubview:navController.view];
[window makeKeyAndVisible];
and then do that in didSelectrow method
[self.navigationController pushViewController:detailedView animated:YES];
Hope this helps.
So I am trying to simple traverse to the next level of a table view by doing this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1) {
FiltersController *aFiltersCont = [[FiltersController alloc] init];
aFiltersCont.displayedFilters = [appDelegate.groupedBusiness allKeys];
aFiltersCont.currentLevel = self.currentLevel + 1;
[self.navigationController pushViewController:self animated:YES];
}
}
is there any reason why this would not be pushing the controller? I had a similar problem before, but solved it by displaying the view modally. However, this time, this is in a popover and needs to slide to the next screen inside that popover. Any Ideas? Thanks in advance.
OK I am going to put some more source up here to try and help...
Inside the main view controller I have this code to make the popover from a button:
// Create and configure the filters controller.
FiltersController *aFiltersController = [[FiltersController alloc] initWithStyle:UITableViewStylePlain];
self.filtersController = aFiltersController;
filtersController.appDelegate = self.appDelegate;
UINavigationController *filtersNavController = [[UINavigationController alloc] initWithRootViewController:filtersController];
UIPopoverController *filtersPopover = [[UIPopoverController alloc] initWithContentViewController:filtersNavController];
self.filtersPopoverController = filtersPopover;
filtersPopoverController.delegate = self;
and then I have the code I first posted in my filtersController class. Does that help at all?
[self.navigationController pushViewController:self animated:YES];
Should be
[self.navigationController pushViewController:aFiltersCont animated:YES];
If you are just displaying your sublcass of UITableViewController inside a UIPopoverController, the UINavigationController will not be created for you automatically. You may need to modify the code where you are creating the UIPopoverController with something like this:
MyTableViewController *table = [[[MYTableViewController alloc] init] autorelease];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:table] autorelease];
myPopover = [[UIPopoverController alloc] initWithContentViewController:nav];
Then you should be able to push and pop navigation controllers on the stack no problem.
you are pushing self which is a reference to the current view controller. you should change the line with the push to the following if aFiltersCont is the viewController you are trying to drill to.
[self.navigationController pushViewController:aFiltersCont animated:YES];
You might be confused about the index. The first index is 0 not 1, so maybe you want indexPath.row == 0?
Also, you should release aFiltersCont before returning (you're leaking a FiltersController and anything it owns every time you run this method.
So maybe this?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
FiltersController *aFiltersCont = [[[FiltersController alloc] init] autorelease];
aFiltersCont.displayedFilters = [appDelegate.groupedBusiness allKeys];
aFiltersCont.currentLevel = self.currentLevel + 1;
[self.navigationController pushViewController:aFiltersCont animated:YES];
}
}