Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 将数据从ViewController传递到UIView_Objective C_Ios_Uiview_Uiviewcontroller - Fatal编程技术网

Objective c 将数据从ViewController传递到UIView

Objective c 将数据从ViewController传递到UIView,objective-c,ios,uiview,uiviewcontroller,Objective C,Ios,Uiview,Uiviewcontroller,可能重复: 我在FirstViewController上有一个带有浮点值的数组。 当用户单击按钮时,我需要将此数组传递给我的视图。 此按钮将调用视图并绘制通知的点。1。 在FirstViewController.h中写入 #include <UIKit/UIKit.h> extern NSArray *yourArray; 现在,您必须在“MyView”类中导入整个FirstViewController。 简单地 #导入“FirstViewController.h” 在MyVie

可能重复:

我在FirstViewController上有一个带有浮点值的数组。 当用户单击按钮时,我需要将此数组传递给我的视图。 此按钮将调用视图并绘制通知的点。

1。 在FirstViewController.h中写入

#include <UIKit/UIKit.h>
extern NSArray *yourArray;
现在,您必须在“MyView”类中导入整个FirstViewController。 简单地 #导入“FirstViewController.h” 在MyView.m。完成此操作后,“yourArray”将在MyView中可用

或者,2.,您可以在MyView.h中写入类似的内容:

- (void)drawRect(NSArray *)yourArray;
在FirstViewController.m中,只需传递数据:(不要忘记#包括MyView.h)

或者,3.,如果您使用的是故事板,您可以

- (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
}
}

谢谢。我在MyView上使用此阵列的时间浪费了2天。第一个答案很有效。
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
}
}