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