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];
}