2010-12-10 10 views
0

quelqu'un L'espoir peut me aider, il m'a totalement déconcertéEnvoyer objet contrôleur UITableView

Mon application a deux contrôleurs de vue dans une barre d'onglets ...

//Create two view controllers 
UIViewController *vc1 = [[RecordingViewController alloc] init]; 
UIViewController *vc2 = [[SavedViewController alloc] init];//this is a tableViewController 

//Make an array with the two view controllers 
NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil]; 

//Release the two view controllers since they are now retained by the array 
[vc1 release]; 
[vc2 release]; 

//Attach the ViewControllers to the tabBar 
[tabBarController setViewControllers:viewControllers]; 

Je puis un autre objet (fileHandler) qui veut envoyer un objet appelé capture-vc2 pour plus d'un NSMutableArray, donc de cette classe ... j'envoie

[vc2 addToCapturesArray:capture]; 

Bien sûr, cela ne fonctionne pas et je reçois simplement le message "vc2 undeclared" du compilateur. Comment puis-je informer ma classe fileHandler de l'instance vc2? Merci d'avance pour toute votre aide.


Merci pour l'aide. Tout compile maintenant, cependant la méthode dans vc2 n'est pas appelée pour une raison quelconque. Le code ressemble maintenant à ceci ...

@interface Rolling_VideoAppDelegate : NSObject <UIApplicationDelegate> { 
UIWindow *window; 

//Tab bar 
UITabBarController *tabBarController; 

//Create an ivar so that the app delegate can hold a reference 
SavedViewController *_vc2; 

} @property (nonatomic, conserver) IBOutlet UIWindow * fenêtre; // Créer une propriété pour que nous puissions accéder à vc2 depuis l'extérieur @property (nonatomic, retain) SavedViewController * vc2;

#import "Rolling_VideoAppDelegate.h" 

//Import view controllers 
#import "RecordingViewController.h" 
#import "SavedViewController.h" 

@implementation Rolling_VideoAppDelegate 

@synthesize window; 
@synthesize vc2 = _vc2; 

#pragma mark - 
#pragma mark Application lifecycle 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  


//Create an instance of tabBarView controller 
tabBarController = [[UITabBarController alloc]init]; 

//Create two view controllers 
UIViewController *vc1 = [[RecordingViewController alloc] init]; 
UIViewController *vc2 = [[SavedViewController alloc] init]; 
self.vc2 = _vc2; 


//Make an array with the two view controllers 
NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil]; 

//Release the two view controllers since they are now retained by the array 
[vc1 release]; 
[vc2 release]; 

//Attach the ViewControllers to the tabBar 
[tabBarController setViewControllers:viewControllers]; 

//Place the tabBar on the window 
[window addSubview:[tabBarController view]]; 

[self.window makeKeyAndVisible]; 

return YES; 

}

Le gestionnaire de fichiers ressemble à ceci ...

Captures *capture = [[Captures alloc]initWithVideoPath:savePath]; 
NSLog(@"Instance of capture called:\n VideoPath: %@ \n Geo: %@, \n UserNotes: %@", [capture videoPath], [capture location], [capture userNotes]); 

// Get a reference to the app delegate, and then access the vc2 property 
Rolling_VideoAppDelegate *appDelegate = (Rolling_VideoAppDelegate*)[UIApplication sharedApplication].delegate; 

[appDelegate.vc2 addToCapturesArray:capture]; 

Merci encore pour toute l'aide.

Rich

+0

Y at-il raison que la classe FileHandler ne peut pas être une variable d'instance dans le second contrôleur de vue? –

+0

Juste pour que vous sachiez, '>' commence un environnement blockquote; indenter par quatre espaces démarre un environnement de code. http://daringfireball.net/projects/markdown/syntax –

+0

Toutes mes excuses pour le balisage. – Shadrax

Répondre

0

En supposant que votre VC1/VC2 sont dans le AppDelegate, alors ce que vous voulez est d'étendre le délégué app quelque chose comme ça

@interface AppDelegate 
{ 
    // Create an ivar so that the app delegate can hold a reference 
    VC2Class *_vc2; 
} 

// Create a property so that you can access if from the outside 
@property(nonatomic, retain) VC2Class *vc2; 

@end 

@implementation AppDelegate 

// Map the property to the ivar 
@synthesize vc2 = _vc2; 

// When you are freeing the app delegate make sure to nil 
// the property to release it 
-(void) dealloc 
{ 
    self.vc2 = nil; 
    [super dealloc]; 
} 

Lorsque vous créez VC2 en plus du reste de votre Code faire ceci:

// Since this is a retain property it will do the retain you need 
// when assigning to self.vc2 
self.vc2 = vc2; 

maintenant dans votre namanger fichier, faites ceci:

// Get a reference to the app delegate, and then access the vc2 property 
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; 
VC2Class *vc2 = appDelegate.vc2; 

Ensuite, vous pouvez appeler comme d'habitude. Assurez-vous d'inclure #import "VC2Class.h" en haut de votre fichier namanger

@end

+1

typo: 'VC2Class * vc2 = appDelegate.vc2;' :-) –

+1

lol merci, c'est comme un compilateur crowdsourcé! :) – MahatmaManic

+0

Problèmes triés avec un peu de jeu autour. Merci beaucoup les gars. – Shadrax