Надеюсь, что кто-то может помочь мне с этим, это поставило меня в тупик
Мое приложение имеет два контроллера представления в панели вкладок ...
//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];
У меня тогда есть другой объект (fileHandler
), который хочет отправить объект с именем capture
в vc2
для добавления к NSMutableArray
, поэтому из этого класса я отправляю ...
[vc2 addToCapturesArray:capture];
Конечно, это не работаети я просто получаю сообщение "vc2 undeclared" от компилятора.Как сообщить классу fileHandler
об экземпляре vc2?Заранее спасибо за вашу помощь.
Спасибо за помощь.Теперь все это компилируется, однако метод в vc2 по какой-то причине не вызывается.Код теперь выглядит следующим образом ...
@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, retain) IBOutlet UIWindow * window;// Создаем свойство, чтобы мы могли обращаться к vc2 извне @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;
}
Обработчик файла выглядит следующим образом ...
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];
Еще раз спасибо за помощь.
Rich