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
Related
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];
I am having problems with getting a detail view to load using pushViewController. At first, I thought pushViewController was not working. BUT, then I tried using a different view controller and it worked. I can tell from tracing that the problem view controller is never loaded at all. In other words, I tried to eliminate the possibility that there was some error in the view controller by NSLoging in that object and I never see anything.
Does anyone have any ideas?
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
NSLog(#"hsitkjsdfkljlkd");
if (childController == nil)
childController = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
//NSUInteger row = [indexPath row];
[self.navigationController pushViewController:childController
animated:YES];
*/
/*
//modal = blocking
salesViewController *otherVC = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
//must set sale type
otherVC.strSaleType = #"Voice";
[self presentModalViewController: otherVC animated:YES];
//No close. By design, it is up to the otherVC to close itself
*/
//tipCalcViewController *detailViewController = [[tipCalcViewController alloc] initWithNibName:#"tipCalcView" bundle:nil];
salesViewController *detailViewController = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
Just Check the
- (void)viewWillAppear:(BOOL)animated
{
}
of the salesViewController.
you are doing something wrong in this..
put the debugging point in the viewWillAppear and run it. you can get the error line..
just try it......Surely it will work for u...
salesViewController *detailViewController = [[salesViewController alloc] initWithNibName:#"salesViewController" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Also make sure you are giving the IBOutlet connection to UIView.
In my case I had several IBOutlets that I removed from the Header file and forgot to remove the connection to these non-existing outlets in Interface Builder. So removing the obsolete outlets fixed the problem in my case.
When you're pushing from ViewController1 to ViewController2 then the code will be used like this so try this code,
ViewController2 *vw2=[[ViewController2 alloc]initWithNibName:#"ViewController2" bundle:nil];
[self.navigationController pushViewController:vw2 animated:YES];
The Above code may be written on Click event of button or on didSelect delegate of UITableView
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];
}
}
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!
Right now I have an indexed UITableView that goes to a detail view but i want it to go to another UITableView then a detail view.
my code like this:
`
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
displyAnnController *anController = [[displyAnnController alloc] initWithNibName:#"AnnView" bundle:[NSBundle mainBundle]];
DetailViewController *dvController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:anController animated:YES];
[anController release];
anController = nil;
break;
case 1:
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
break;
default:
break;
}`
and when I press the cell with index 0 in the simulator, the program is crash!
what's the problem? pleas help me ..
No, I didn't override the -initWithNibName, I just use it as the same way here,but to push to ControlView NOT TableView.Also,no errors in debug console.
and I have tried to release the controllers after the switch block, but the program still crash :(
anyway, it's work when I write:
displyAnnController *anController = [[displyAnnController alloc] initWithStyle:UITableViewStyleGrouped]];
instead of :
displyAnnController *anController = [[displyAnnController alloc] initWithNibName:#"AnnView" bundle:[NSBundle mainBundle]]
Temporarily, I accept this just to complete my work! but I hope to find any help example because no need to be as group.
thanks all for help and recommendations.
View the debug console (Cmd-Shift-R) and see what the error is.
Are you overriding the -initWithNibName message on displyAnnController? Or the -viewDidLoad message?
You also have a memory leak. You always +alloc both controllers, but only -release one of them. Don't +alloc your controller unless you are going to actually use it.
I think your application is crashing because first you have released the view and then you are making it nil.If it is released once then it is not getting the reference to make it nil.Try it once.It may work.