1.在跳轉前的視圖控制器類中實現prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destination = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
NSArray *onleWords = [queryWords allKeys];
NSString *onleWord = [onleWords objectAtIndex:indexPath.row];
Word *word = [queryWords objectForKey:onleWord];
NSDictionary *selectionDetail = [NSDictionary dictionaryWithObjectsAndKeys:
word, @"object",
nil];
[destination setValue:selectionDetail forKey:@"selectionDetail"];
if ([destination respondsToSelector:@selector(setDelegate:)]) {
[destination setValue:self forKey:@"delegate"];
}
if ([destination respondsToSelector:@selector(setSelection:)]) {
// prepare selection info
}
}
2.定義跳轉後的.h文件
#import <UIKit/UIKit.h>
@interface CYLDetailWordViewController : UITableViewController
@property (copy, nonatomic) NSDictionary *selectionDetail;
@property (weak,nonatomic) id delegate;
@property (weak, nonatomic) IBOutlet UILabel *wordLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneticLabel;
@property (weak, nonatomic) IBOutlet UILabel *transLabel;
@end
3.在.m文件中viewDidLoad方法中做用這些數據想實現的功能
- (void)viewDidLoad
{
[super viewDidLoad];
Word *word = [selectionDetail objectForKey:@"object"];
wordLabel.text = [word word];
phoneticLabel.text = [word phonetic];
transLabel.text = [word trans];
}