首先讓我爲我的壞英語道歉。所以我試圖做這個程序,從另一個類中獲取一個類的NSString的值。這裏的代碼:iPhone:從另一個類訪問NSString值
/---------------------/tableViewController.h -----------
#import <UIKit/UIKit.h>
@class paisesDetailViewController;
@interface tableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
IBOutlet UITableView *paisesTableView;
paisesDetailViewController *PaisesDetailViewController;
//DB
NSString *DBName;
NSString *DBPath;
NSMutableArray *ArrayPais; //means Countrys
NSString *escolha; //means choise
}
@property(nonatomic, retain) paisesDetailViewController *PaisesDetailViewController;
@property(nonatomic, retain) NSMutableArray *ArrayPais;
@property(nonatomic, retain) NSString *escolha;
@end
-----------------------------//tableViewController.m---------------
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
if(self.PaisesDetailViewController == nil)
{
paisesDetailViewController *apaisesDetail = [[paisesDetailViewController alloc] initWithNibName:@"paisesDetailView" bundle:nil];
self.PaisesDetailViewController = apaisesDetail;
[apaisesDetail release];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
escolha = [[NSString alloc] init];
self.escolha = [NSString stringWithFormat:@"%@", [ArrayPais objectAtIndex:(row)]];
paisesDetailViewController *nextview = [[paisesDetailViewController alloc] init];
[self.navigationController pushViewController:nextview animated:YES];
[nextview release];
}
-----------------------------------//paisesDetailViewController.h------------
#import <UIKit/UIKit.h>
#import "tableViewController.h"
@class tableViewController;
@interface paisesDetailViewController : UIViewController {
tableViewController *dados;
}
@property(nonatomic, retain) tableViewController *dados;
@end
//-----------------------paisesDetailViewController.m
#import "paisesDetailViewController.h"
#import "tableViewController.h"
@implementation paisesDetailViewController
@synthesize dados;
-(IBAction) createEvent
{
NSString *help = [[NSString alloc] initWithString: dados.escolha];
}
問題是,'dados.escolha'總是零,我只是不明白爲什麼。 感謝您的幫助。
這樣做了。謝謝。但要解決它,我不得不做* dados = [[tableViewController alloc] init];每當我做到這一點時,我總是得到零。現在它的工作,這就是metter :) Thks – JTFerreira
Superbbb Man ... it Worked ... nextView.dados = self;我正在尋找類似場景的解決方案,並最終解決上述問題。非常感謝... –