FirstViewController.h访问变量:从另一个视图控制器
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
{
NSArray *listData;
}
-(IBAction) GoToInsert: (id) sender;
@property (nonatomic, retain) NSArray *listData;
@end
FirstViewController.m:
-(IBAction) upisiRezultat:(id)sender
{
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName: nil bundle: nil];
[self presentModalViewController: secondView animated: NO];
[secondView release];
}
- (void)viewDidLoad
{NSArray *array = [[NSArray alloc] initWithObjects:@"236", @"46",
@"147", @"8", @"56", @"69", @"114", @"2",
@"96", @"518", @"2", @"54", @"236", nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
SecondViewontroller.h
@interface SecondViewController : UIViewController {
}
-(IBAction) insert;
@end
SecondViewontroller.m
-(IBAction) insert
{
/* Here should be the code to insert some number in listData from FirstViewController */
}
所以,当应用程序加载它加载FirstViewController.xib并在屏幕上显示的listData阵列,当我点击按钮“去插入”另一种观点被加载(SecondViewController.xib )与“插入”按钮,它应该添加一些数字到数组中,并在第一个视图上显示新的数组。
如何做到这一点?
更具可读性的代码: http://pastebin.com/GBk1V7ac – vburojevic
您可以在Stack Overflow上格式化代码,在单击'{}'时写入题。 – ryyst
@Wikiboo:让我知道如果该代码有帮助! – Legolas