Iphone 将对象发送到UITableView控制器
希望有人能帮我,这让我很困惑 我的应用程序在选项卡栏中有两个视图控制器Iphone 将对象发送到UITableView控制器,iphone,ios,uitableview,Iphone,Ios,Uitableview,希望有人能帮我,这让我很困惑 我的应用程序在选项卡栏中有两个视图控制器 //Create two view controllers UIViewController *vc1 = [[RecordingViewController alloc] init]; UIViewController *vc2 = [[SavedViewController alloc] init];//this is a tableViewController //Make an array with the two
//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未声明”消息。如何让我的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;
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];
}
文件处理程序如下所示
@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;
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假设您的vc1/vc2在AppDelegate中,那么您想要的是像这样扩展AppDelegate
@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;
然后你可以像平常一样打电话给它。确保在文件的顶部包含导入“VC2Class.h”
@end是否有任何原因导致fileHandler类不能成为第二个视图控制器中的实例变量?正如您所知,
启动blockquote环境;按四个空格缩进将启动代码环境。打字错误:VC2Class*vc2=appDelegate.vc2代码>:-)通过一些小游戏解决问题。非常感谢各位。