2012-11-08 176 views

回答

1

在你FirstViewController.h写

#include <UIKit/UIKit.h> 
extern NSArray *yourArray; 

而在你FirstViewController.m写

#import "FirstViewController.h" 
@interface FirstViewController() 
@end 
NSArray *yourArray; 

现在你必须导入整个FirstViewController在“MyView的“-类。 只需要 #在MyView.m中导入“FirstViewController.h” 。这样做后,“yourArray”将在MyView中可用。

或者,2.,你可以写这样的事情到MyView.h:

- (void)drawRect(NSArray *)yourArray; 

,并在您FirstViewController.m,简单地传递数据:(不要忘记#包括MyView的.H)

MyView *myView = [[MyView alloc]init]; 
[myView drawRect:yourArray]; //You'll have to pass "yourArray", to the function in MyView, which is going to be called 

或者,,如果你使用的故事板,你可以

- (IBAction)pushedButton(UIButton *)sender { 
[self performSegueWithIdentifier:@"pushButton" sender:self]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
if ([segue.identifier isEqualToString:@"pushButton"] { 
MyView *destinationViewController = segue.destinationViewController; 
destinationViewController.yourArray = yourArray; // you'll have to define yourArray in the .h File 
} 
} 
+0

非常感谢。我失去了2天试图在MyView上使用这个数组。第一个答案很好。 –

相关问题