DetailView not opening from UITableViewController press (iOS Xcode) - objective-c

Inside my TableView, I am pressing one of the cells to enter the detailed view, and for some reason it won't take me to the detailed view. Does anyone see a problem in the below code?
For context, this is a teacher directory, and pressing one of the cells brings up the teachers picture and other info.
Thanks for the help...if you need any more info I can add it in.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the selected teacher
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:#"Teachers"];
NSString *selectedTeacher = [array objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
dvController.selectedTeacher = selectedTeacher;
[self.navigationController pushViewController:dvController animated:YES];
dvController = nil;
}

You should check if dvController is correctly loaded, so try to NSLog dvController once you have called the alloc-init. Another way to instantiate it is to use this simple call which works if you created the view controller and the xib together:
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
Besides there is no reason to nil dvController at the end. If you're concerned with memory management, that is you don't want to leak dvController, simply autorelease it. So replace:
dvController=nil;
with:
[dvController autorelease];
this works because the navigation controller retains the pushed view controller
(or use ARC).
Finally I assume the tableView:didSelectRowAtIndexPath: is called... if not sure, just a place a breakpoint.

I don't know if you ever resolved your problem, but I was having the same problem where my Detail View was not appearing. I finally replaced
[self.navigationController pushViewController:dvController animated:YES];
with
[self presentModalViewController:dvController animated:YES];
and it worked. Hope that helps.

Related

detailview screen can not open with pushViewController in a tableview

I have a tabbar in my project and each tab bar has a tableview.
I want to open a detail screen when click a row in a tableview as follows. But nothing happens.
Where's the mistake I'm doing. How should I set up a logic.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:#"DetailScreen" bundle:nil];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
}
There are many possible reasons nothing is happening when you click on a cell.
Put a break point in this method. Is It even being called?
After the App has stopped at the breakpoint, go to the console type po detail after the instance is initialised. Make sure it's not (null)
Also try typing po [self navigationController] to check whether the navigation controller exists.
You've probably not got a navigation controller. How are you creating the tabbarcontroller? in interface builder or through code in the AppDelegate's didFinishLaunchingWithOptions: method?
Have you done this?
YourViewController *yourVC = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourVC];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, nil];
try this,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailScreen *detail = [[DetailScreen alloc] init];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
}
I guess you don't have a navigation controller so
[self.navigationController pushViewController:detail animated:YES];
will not work.
use
[self.view addSubview:detail.view]
or
[self presentModalViewController:detail animated:YES];
instead
If your project is UITabBarViewController based application, i dont think your can navigate to another view using pushViewController unless you have navigationController in your project.
Add your view controller(your table view containing controller) into navigation controller and then start using
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:#"DetailScreen" bundle:nil];
[self.navigationController pushViewController:detail animated:YES];
[self.navigationController pushViewController:detail animated:YES];
Instead move your detail push code to another method and call:
[self performSelector:#selector(myMethod:) withObject:nil]

Online Tutorial Not Working, Request for Member not in a structure or Union?

I'm new to iOS Development, so I've been following a bunch of tutorials online on how to make drill-down applications. I've run into this problem on two builds and I can't seem to get over it. I'm creating a tab bar application. In my app delegate, I define a tab bar, navigation controller, view controller, and an NSDictionary for my .plist. Problem is, when I get to my ViewController.m's file and start telling it to use the navigation controller i created, I get the error "Request for member is something not a structure or union."
I've tried this twice, quadrupled checked the code, and I still don't get it. Any help would be greatly appreciated :)
Below is the tableView method from my ViewController.m file.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:#"Children"];
if([Children count] == 0) {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:[NSBundle mainBundle]];
[self.indNavControl pushViewController:dvController animated:YES];
[dvController release];
}
else {
//Prepare to tableview.
IndustriesViewController *indViewControl = [[IndustriesViewController alloc] initWithNibName:#"IndustryView" bundle:[NSBundle mainBundle]];
//Increment the Current View
indViewControl.CurrentLevel += 1;
//Set the title;
indViewControl.CurrentTitle = [dictionary objectForKey:#"Title"];
//Push the new table view on the stack
[self.indNavControl pushViewController:indViewControl animated:YES];
indViewControl.tableDataSource = Children;
[indViewControl release];
}
}
did you synthesize indNavControl?

Error: unrecognized selector sent to instance

I have a custom object, Spaces:
#import "Spaces.h"
#implementation Spaces
#synthesize spaceName;
#synthesize spaceUsers;
#synthesize spaceIcon;
#synthesize spaceID;
#synthesize imageURLString;
- (void)dealloc
{
[spaceName release];
[spaceUsers release];
[spaceIcon release];
[imageURLString release];
[super dealloc];
}
#end
My root view controller implements a cellForRowAtIndexPath: and grabs from an NSArray of Spaces:
[[cell spaceName] setText:aSpace.spaceName];
[[cell spaceChatType] setText:#"People"];
[[cell spaceActiveUsers] setText:aSpace.spaceUsers];
This works fine and I can click to go into the detail view and back to the list, but after maybe 5-6 clicks back and forth between the table view and detail view, I get an error at [[cell spaceName] setText:aSpace.spaceName]; which is
'-[__NSCFSet spaceName]: unrecognized selector sent to instance 0x6047b90'"
Please help! Any insight will be very appreciated!
UPDATE:
I'm still getting the same error but I've narrowed it down to the this:
-I'm creating a detail view controller on didSelectRowAtIndexPath...
-The detail view is being pushed to the viewcontroller and displays fine, I have a back button added as well.
-The detail view loads information and refreshes on a timer
-Pressing the back button goes back to the table list view
This is the problem my detail view is not being released from memory so the more I go back and forth between the views the more timers were going off simultaneously. I added a check to viewWillDisappear that stops the timer by setting a bool value.
I noticed that the detail view is not unloading...
From the RootViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//no longer on initial view
isinit = NO;
//hide keyboard
[spacesSearch resignFirstResponder];
if (spaces != nil && spaces.count > 0)
{
//set back button reference
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Spaces" style:UIBarButtonItemStylePlain target:self action:#selector(returnSpacesList:)];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
DetailViewController *details = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
//Grab Data from selected Space object and pass to DetailViewController
Spaces *aSpace = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
if ([self.filteredListContent count] == 0)
{
//self.lastSearchText
NSLog(#"Create new space code!");
}
else
{
aSpace = [self.filteredListContent objectAtIndex:indexPath.row];
}
}
else
{
aSpace = [spaces objectAtIndex:[indexPath row]];
}
//set title and display
self.navigationController.title = [NSString stringWithFormat:#"/%#/",aSpace.spaceName];
//pass data
[details passedValue:aSpace.spaceID :aSpace.spaceName];
[self.navigationController pushViewController:details animated:YES];
[aSpace release];
[details release];
}
}
How can I force the detail view to be released from memory?
Thank you
It sounds like [cell spaceName] has been autoReleased. I cannot see how you have defined that, but take a look at that part of your code.
If you need more help, you need to provide more code.
Perhaps your aSpace = [spaces objectAtIndex:[indexPath row]];
is not returning a Space object. Perhaps before you try and use it you test to make sure with something like if ([aSpace class] == [Spaces class])

didSelectRowAtIndexPath problem

I have a problem that I had working in a test but now in a bigger application I can't seem to sort out.
First of I have a view that has six button each loads a different view I am using:
- (IBAction)showInfo2:(id)sender {
InfoViewController *Infocontroller = [[[InfoViewController alloc] initWithNibName:#"InfoView" bundle:nil] autorelease];
Infocontroller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:Infocontroller animated:YES];
}
This seems to be working fine, and loads the next section, in this case 'infoview'.
I then load a tableview and fill it full f data from an xml feed, this again is now working, (although was not an easy task for me!).
The problem comes when I know try and use:
Nothing seems to happen, ie, the new view is not loaded.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
SubInfoViewController *subInfoViewController = [[SubInfoViewController alloc] initWithNibName:#"SubInfoView" bundle:nil];
[self.navigationController pushViewController:subInfoViewController animated:YES];
[subInfoViewController release];
}
I know its being called because this works:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *message = [[NSString alloc] initWithFormat:#"You selected a row"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Row Selected" message:message delegate:nil cancelButtonTitle:#"Yes I did" otherButtonTitles:nil];
[alert show];
[message release];
[alert release];
}
Any help more than welcome, and please be gentle newbie :)
You're view is probably push into navigation stack but you can't see it because your parent view is modal.
You can't try to display your SubInfoViewController like this :
SubInfoViewController *subcontroller=[[SubInfoViewController alloc] initWithNibName:#"SubInfoViewController" withBundle:nil];
[self presentModalViewController:subcontroller animated:YES];
[subcontroller release];
If you want to keep a navigation logic in your app, you should not display your InfoViewController modally but present it in a common way in your navigation stack.
You can try to dismiss your modal view before pushing your SubViewController. In this case you must do something like this :
SubInfoViewController *controller=[[SubInfoViewController alloc] initWithNibName:#"SubInfoViewController" bundle:nil];
[self.parentViewController pushViewController:controller animated:YES];
[self dismissModalViewControllerAnimated:YES];
[controller release];
You'll receive a warning because parentViewController may not respond to pushViewController: animated: but with a NSLog you'll see that your parentViewController is actually a UINavigationController.
Hope this helps !
What exactly is the problem? Your code looks fine at first glance.

Objective-C TableView Select Item Troubles

I'm having trouble having my app respond when an Item is selected in the table view. I'm running everything from my app delegate (the table functions that is like dataSource and TitleForHeaderAtSection etc) which are all being called fine. However it is not calling my selection method when I tap on a item in the list. I even put a NSLog to see just in case.
Here's my code: (its quite long and extensive and I know theres crap in there that doesn't need to be there but I put all of it just in case you needed it...)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Selected Row.", #"");
//Get the selected country
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSDictionary *dictionary = [data objectAtIndex:indexPath.section];
//NSArray *array = [dictionary objectForKey:#"My Wishlists"];
//NSString *selectedWishlist = [array objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
WishlistDetailView *dvController = [[WishlistDetailView alloc] initWithNibName:#"WishlistDetailView" bundle:[NSBundle mainBundle]];
dvController.selectedWishlistId = [wishlistids objectAtIndex:indexPath.row];
NSLog(#"Selected row with wishlist id: %#", dvController.selectedWishlistId);
[[self navController] pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
The code compiles with NO errors.
Thanks for your persistant help!!
Christian Stewart
(by the way both of the selection allowed checkboxes are checked in Interface builder.)
tableView:didSelectRowAtIndexPath: is a UITableViewDelegate method. Is you controller the delegate of the table view?