Problem with SplitViewController
I have a problem with the splitviewcontroller. I have the code below and when i run the app, and pressing the rootviewcontroller, which is a table, the next view appeared in the rootviewcontroller part but not the detailview. May I know which part of code i did wrong?
Many Thanks
- (UITableViewCell *)tableView:(UITableView *)tableView开发者_StackOverflow cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell
Travel_Packer_HDAppDelegate *appDelegate = (Travel_Packer_HDAppDelegate *)[[UIApplication sharedApplication] delegate];
Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];
[cell setText:animal.name];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
Travel_Packer_HDAppDelegate *appDelegate = (Travel_Packer_HDAppDelegate *)[[UIApplication sharedApplication] delegate];
Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];
if(self.animalView == nil) {
DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
self.animalView = viewController;
[viewController release];
}
// Setup the animation
[self.navigationController pushViewController:self.animalView animated:YES];
// Set the title of the view to the animal's name
self.animalView.title = [animal name];
// Set the description field to the animals description
[self.animalView.animalDesciption setText:[animal description]];
// Load the animals image into a NSData boject and then assign it to the UIImageView
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]];
UIImage *animalImage = [[UIImage alloc] initWithData:imageData cache:YES];
self.animalView.animalImage.image = animalImage;
}
As I understood you have navigation controllers in each pane of split view controller? Then probably the issue in next line:
[self.navigationController pushViewController:self.animalView animated:YES];
due to you've just pushed the animalView to left navigation controller but you need right (detail pane) one.
精彩评论