希望有人可以帮助我,这让我完全难过
我的应用程序在标签栏中有两个视图控制器......
//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 unclared”消息。如何让我的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(非原子,保留)IBOutlet UIWindow *窗口; //创建一个属性,以便我们可以从外部访问vc2 @property(非原子,保留)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];
再次感谢您的帮助。
富
答案 0 :(得分:0)
假设你的vc1 / vc2在AppDelegate中,那么你想要的是扩展app delegate这样的东西
@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];
}
除了代码的其余部分创建vc2之外,请执行以下操作:
// Since this is a retain property it will do the retain you need
// when assigning to self.vc2
self.vc2 = vc2;
现在在你的文件namanger中,执行以下操作:
// Get a reference to the app delegate, and then access the vc2 property
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
VC2Class *vc2 = appDelegate.vc2;
然后你就可以正常打电话了。请务必在文件顶部包含#import "VC2Class.h"
@end