好,以縮短代碼有點..
if([segue.identifier isEqualToString:@"pushToMountainInfo"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
MountainInformation *destViewController = [segue destinationViewController];// do this only if your segue is connected to the next one from previous, or else let it stay as you have, only change the later part
MountainsObject *mountain = [self.mountains objectAtIndex:indexPath.row];
destViewController.myMountain = mountain.name;
NSLog(@"%@", mountain.name);
}
現在創建MountainInformation.h屬性文件
@property (nonatomic, strong) NSString* myMountain;
現在你的屬性設置爲你想要設置的名稱。現在 在viewDidLoad中的MountainInformation.m
-(viewDidLoad){
self.labelToShowName.text = self.myMountain;
}
希望這有助於
[編輯] 在MountainInformation.h導入你的山類。
#import "MountainObject.h"
更改屬性
@property(nonatomic, strong) MountainObject *selectedMountain
現在,在以前的視圖控制器。
if([segue.identifier isEqualToString:@"pushToMountainInfo"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *nav = segue.destinationViewController;
MountainObject *mountain = [self.mountain objectAtIndex.indexPath.row];
destViewController.selectedMountain = mountain;
}
在MountainInformation.h
-viewDidLoad{
NSString *mountainName = self.selectedMountain.name;
NSString *mountainRegion =self.selectedMountain.region;
NSString *mountainHeight =self.selectedMountain.height;
//and other properties. and then you can set it to a single label by using
self.myLabel.text = [NSString stringWithFormat:@" Name - %@, Height- %@, Region- %@",mountainName, mountainHeight, mountainRegion];
}
太謝謝你了!我必須保留uinavigationcontroller代碼,因爲我的視圖已連接到一個,但現在它可以從您的代碼中運行。 非常感謝你:) – Gethin 2015-03-03 12:21:29
沒問題,請接受答案,以便如果有人遇到同樣的問題,他們可以幫助自己的答案,歡呼 – 2015-03-03 12:22:16
會做:)它告訴我,我必須等待幾分鐘,但預先。 .. – Gethin 2015-03-03 12:23:59