Partage
  • Partager sur Facebook
  • Partager sur Twitter

[iPad] Changer le contenu du DetailViewController

Sujet résolu
    22 mai 2012 à 23:27:06

    Bonjour tout le monde !

    Je suis nouveau dans la programmation d'application d'appareil iOS. J'essaie présentement de créer une application iPad qui comportera une page principale (de login) qui mènera à un tabbarcontroller. Une des onglets de ce tabbarcontroller sera un splitviewcontroller. J'ai réussie a créer tout cela en utilisant le storyboard, cependant je n'arrive pas à faire changer le contenu du detailviewcontroller avec le masterviewcontroller. Quand je clique sur la tag qui me conduit au splitview c'est correcte. Cependant, rendu au splitview, quand je clique sur les différentes cellules du tableview, le detailview reste noir.

    Merci bien de vouloir m'aider.

    Voici le code de mon application :
    (Je n'ai pas mis le code pour la classe tree, je ne crois pas que c'est utile pour règler mon problème)
    J'ai comme l'impression que c'est peut-être dans AppDelegate le problème, mais comme je vous l'ai dit, je suis nouveau, donc je ne sais pratiquement pas quoi rajouter dans AppDelegate

    MasterViewController.m
    #import "MasterViewController.h"
    #import "DetailViewController.h"
    
    @implementation MasterViewController
    
    @synthesize detailViewController,detailObject, menuItems;
    
    -(void)awakeFromNib{
        self.clearsSelectionOnViewWillAppear = YES;
        self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
        [super awakeFromNib];
    }
    
    -(void)viewDidLoad{
        [super viewDidLoad];
        self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
    }
    
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    //define how many items will appear in each row
        return 1;
    }
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        // define the number of items that will be listed on table
        return [self.LoadMenuItems count];
    }
    
    -(NSArray *)LoadMenuItems{
        
        NSMutableArray * menuData =  [[NSMutableArray alloc] initWithCapacity:5];
        Trees * tree = [[Trees alloc] init];
        
        tree.treeName = @"Oak";
        tree.treeDescription = @"An oak is a tree or shrub oak tree, of which about 600 species exist. The Oak is native to the northern hemisphere, and includes deciduous and evergreen species extending from cool temperate to tropical latitudes in Asia and the Americas.";
        NSString * file = [[NSBundle mainBundle] pathForResource:@"oak" ofType:@"jpg"];
        tree.treePhoto = [UIImage imageWithContentsOfFile:file];  
        
        [menuData addObject:tree];
        tree=nil;
        
        tree = [[Trees alloc] init];
        tree.treeName = @"Douglas Fir";
        tree.treeDescription = @"Douglas-firs are medium-size to extremely large evergreen trees, 20â120 metres (70â390 ft) tall (although only Coast Douglas-firs reach such great height). The leaves are flat, soft, linear. They completely encircle the branches, which can be useful in recognizing the species. The female cones are pendulous, with persistent scales (unlike true firs), and are distinctive in having a long tridentine (three-pointed) bract that protrudes prominently above each scale (it resembles the back half of a mouse, with two feet and a tail).";
        file = [[NSBundle mainBundle] pathForResource:@"DouglasFir" ofType:@"jpg"];
        tree.treePhoto = [UIImage imageWithContentsOfFile:file];  
        [menuData addObject:tree];
        tree=nil;
        
        tree = [[Trees alloc] init];
        tree.treeName = @"Sugar Maple";
        tree.treeDescription = @"Sugar Maple is a species of maple native to the hardwood forests of northeastern North America, from Nova Scotia west to southern Ontario, and south to Georgia and Texas.[2] Sugar maple is best known for its bright fall foliage and for being the primary source of maple syrup.";
        file = [[NSBundle mainBundle] pathForResource:@"SugarMaple" ofType:@"jpg"];
        tree.treePhoto = [UIImage imageWithContentsOfFile:file];  
        [menuData addObject:tree];
        tree=nil;
        
        tree = [[Trees alloc] init];
        tree.treeName = @"Red Maple";
        tree.treeDescription = @"Red Maple is one of the most common and widespread deciduous trees of eastern North America. It ranges from the Lake of the Woods on the border between Ontario and Minnesota, east to Newfoundland, south to near Miami, Florida, and southwest to east Texas. Many of its features, especially its leaves, are quite variable in form. At maturity it often attains a height of around 15 m (50 ft). It is aptly named as its flowers, petioles, twigs and seeds are all red to varying degrees. Among these features, however, it is best known for its brilliant deep scarlet foliage in autumn.";
        file = [[NSBundle mainBundle] pathForResource:@"RedMaple" ofType:@"jpg"];
        tree.treePhoto = [UIImage imageWithContentsOfFile:file];  
        [menuData addObject:tree];
        tree=nil;
        
        tree = [[Trees alloc] init];
        tree.treeName = @"Pine";
        tree.treeDescription = @"Pines are trees in the genus Pinus. They make up the monotypic subfamily Pinoideae. There are about 115 species of pine, although different authorities accept between 105 and 125 species.";
        file = [[NSBundle mainBundle] pathForResource:@"Pine" ofType:@"jpg"];
        tree.treePhoto = [UIImage imageWithContentsOfFile:file];  
        [menuData addObject:tree];
        
    
        menuItems = [[NSArray alloc] initWithArray:(NSArray *)menuData];
        tree=nil;
        
        return menuItems;
    }
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *CellIdentifier = @"menuSelection";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        
        Trees *myTree = [self.LoadMenuItems objectAtIndex:indexPath.row];
        cell.textLabel.text = myTree.treeName;
        
        return cell;
    }
    
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        
        Trees *selectedTree = (Trees *)[self.menuItems objectAtIndex:[self.tableView indexPathForSelectedRow].row];
        
        detailObject = selectedTree;
        [detailViewController setDetailItem:detailObject];
        
    }
    
    
    
    @end
    

    MasterViewController.h
    #import <UIKit/UIKit.h>
    #import "Trees.h"
    #import "detailViewController.h"
    
    
    @class DetailViewController;
    
    @interface MasterViewController : UITableViewController<UITableViewDelegate> 
    
    @property (nonatomic, strong) IBOutlet DetailViewController *detailViewController;
    @property (nonatomic, strong)id detailObject;
    @property (nonatomic, strong) NSArray *menuItems;
    
    -(NSArray *)LoadMenuItems;
    
    @end
    


    DetailViewController.m

    //
    //  DetailViewController.m
    //  test1
    //
    //  Created by Jonathan Lafrance on 12-05-22.
    //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    //
    
    #import "DetailViewController.h"
    
    
    @implementation DetailViewController
    @synthesize detailItem,detailImage,detailDescription,masterPopOverController;
    
    -(void)setDetailItem:(id)newDetailItem{
        if (detailItem != newDetailItem) {
            detailItem = newDetailItem;
            
            //update the view
            [self configureView];
        }
        
        //this is for the portrait mode to dismiss the menu
        
        if(self.masterPopOverController !=nil){
            [self.masterPopOverController dismissPopoverAnimated:YES];
        }
    }
    
    -(void)configureView{
        //update the user interface for the detail item.
        Trees *aTree = (Trees *)self.detailItem;
        
        self.detailDescription.text = aTree.treeDescription;
        self.detailImage.image = aTree.treePhoto;
    }
    
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)loadView
    {
        // If you create your views manually, you MUST override this method and use it to create your views.
        // If you use Interface Builder to create your views, then you must NOT override this method.
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)viewDidUnload
    {   
        [self setDetailDescription:nil];
        [self setDetailImage:nil];
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    @end
    


    DetailViewController.h

    //
    //  DetailViewController.h
    //  test1
    //
    //  Created by Jonathan Lafrance on 12-05-22.
    //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    #import "Trees.h"
    
    @class Trees;
    @interface DetailViewController : UIViewController
    @property(strong, nonatomic) id detailItem;
    @property(strong, nonatomic) UIPopoverController *masterPopOverController;
    -(void)configureView;
    @property(retain, nonatomic) IBOutlet UITextView *detailDescription;
    @property(retain, nonatomic) IBOutlet UIImageView *detailImage;
    @end
    


    AppDelegate.h
    //
    //  AppDelegate.h
    //  test1
    //
    //  Created by Jonathan Lafrance on 12-05-18.
    //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    //
    
    @class MasterViewController;
    @class DetailViewController;
    
    @interface AppDelegate : NSObject <UIApplicationDelegate> {
        
        UIWindow *window;
        
        
    }
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    
    
    
    @end
    

    AppDelegate.m
    //
    //  AppDelegate.m
    //  test1
    //
    //  Created by Jonathan Lafrance on 12-05-18.
    //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    //
    
    #import "AppDelegate.h"
    
    #import "MasterViewController.h"
    #import "DetailViewController.h"
    
    @implementation AppDelegate
    
    @synthesize window;
    
    - (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        
        /* Override point for customization after app launch    
        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate =(id)navigationController.topViewController;
        */
            return YES;
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application {
        // Save data if appropriate
    }
    @end
    
    • Partager sur Facebook
    • Partager sur Twitter
      23 mai 2012 à 9:13:34

      Bonjour,

      J'ai édité le titre de ton sujet pour qu'il soit conforme aux règles du forum "Mobile" et du site (il faut indiquer le plateforme entre crochet et donner un titre explicite "Problème application" n'est pas explicite sur ton problème). J'ai aussi modifier le langage de tes balises code pour le bon langage. Tu ne programmes pas en C# sur iPad. :)

      Merci de faire attention la prochaine fois.

      PS : Si le titre ne te convient pas, contact moi par MP. Le forum "Mobile" souffre d'un bug qui empêche les membres de modifier le titre de leurs sujets eux-même.
      • Partager sur Facebook
      • Partager sur Twitter
      Si vous voulez me retrouver, rendez-vous sur ZesteDeSavoir.

      [iPad] Changer le contenu du DetailViewController

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown