Possible Duplicate:
Passing Data between View Controllers
我在FirstViewController上有一个带有浮点值的数组。
当用户单击按钮时,我需要传递给“查看此数组”。
该按钮将调用视图并绘制通知的点。
最佳答案
1。
在您的FirstViewController.h中编写
#include <UIKit/UIKit.h>
extern NSArray *yourArray;
并在您的FirstViewController.m中编写
#import "FirstViewController.h"
@interface FirstViewController ()
@end
NSArray *yourArray;
现在,您必须将整个FirstViewController导入“ MyView”类中。
只是
#import“ FirstViewController.h”
在MyView.m中。这样做之后,“ yourArray”将在MyView中可用。
或者,2.您可以在MyView.h中编写如下代码:
- (void)drawRect(NSArray *)yourArray;
并在您的FirstViewController.m中,简单地传递数据:(不要忘记#include 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
或者,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
}
}
关于objective-c - 将数据从ViewController传递到UIView ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13298180/