0
可能重复:
Passing Data between View Controllers从视图控制器将数据传递到的UIView
我有FirstViewController与浮点值的数组。 当用户点击一个按钮时,我需要传递给我的View this array。 此按钮将调用视图并绘制通知的点。
可能重复:
Passing Data between View Controllers从视图控制器将数据传递到的UIView
我有FirstViewController与浮点值的数组。 当用户点击一个按钮时,我需要传递给我的View this array。 此按钮将调用视图并绘制通知的点。
在你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
}
}
非常感谢。我失去了2天试图在MyView上使用这个数组。第一个答案很好。 –