Reputation: 123
I have an app in portrait, in my View Controller (UIViewController
, not a UITableViewController
) there is a table (UITableView
) that only occupies half the screen.
I set the delegate and datasource of my table view to my view controller.
Now, I would like to show a detail view when i select any cell of my table. Here is what I tried but nothing appears:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"SELECTED");
//ChangeView
DetailViewController *dvController = [[DetailViewController alloc]
initWithNibName:@"DetailViewController" bundle:nil];
[self.navigationController pushViewController:dvController animated:YES];
dvController = nil;
}
Any idea? Is this solution better than a popup solution?
Upvotes: 0
Views: 1348
Reputation: 750
You Should check your tableview in nib file it datasource and delegate is connected or not? just connect both with file owner.
and if you are using uiview controller then use present model view controller not push modelview controller.
DetailViewController *dvc=[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
[self presentModalViewController:dvc animated:YES];
Upvotes: 2
Reputation: 688
Put [NSBundle mainBundle]
in place of nil. Hope it helps. Tell me what happens!
Also replace dvController=nil;
with [dvController release];
EDIT: Replace ur init function with this one:
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
Upvotes: 2
Reputation: 362
You should check if didSelectRowAtIndexPath
is really called or not when you select a table cell (of not, your delegate may not be set correctly), then if
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
returns nil or something meaningful with a debugger, trying to close in on the problem. Also, @M.A.Khan was right, you should remove
dvController = nil;
and replace it with
[dvController release];
giving up the reference in your main view.
Edit:
Your code asumes that beneath your UIViewController, there is a UINavigationController because you're using [self.navigationController pushViewController]
. If there isn't, no wonder your view does not get pushed onto something that doesn't exist.
Upvotes: 1
Reputation: 8947
initialize navigation controller. becauze some time it is due to ui component which has not initialized. but remember that you may have to face some other UI issues
Upvotes: 1
Reputation: 2822
is the viewcontroller with tableview in a navigationcontroller?if not then first you have to create a navigationcontroller with the current viewcontroller as the rootviewcontroller.then try this code u are using now
Upvotes: 0