我正在做主+详细信息页面。我已使用以下代码成功点击母版页中的单元格行跳转到详细信息页
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"MasterToDetail" sender:indexPath];
}
但是因为我的母版页单元格行也有辅助按钮,所以我需要通过点击使这些按钮也能够跳转到详细信息页面。所以我实现了代码
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"MasterToDetail" sender:self];
}
但是显示的详细信息不正确。它始终显示数据列表中的第一个详细数据。我将 sender:self 更改为 sender:indexPath 也不起作用。
我从这里和这里使用了 stackoverflow 的答案。我是初学者,所以有些概念还是不清楚对不起。
已编辑 - masterviewcontroller.m 的准备工作
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DetailViewController *detailController =segue.destinationViewController;
SearchDataDetail *bug = [self.bugs objectAtIndex:self.tableView.indexPathForSelectedRow.row];
detailController.detailItem = bug;
}
-detailviewcontroller.m
#import "DetailViewController.h"
#import "SearchData.h"
#import "SearchDataDetail.h"
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
- (void)configureView
{
// Update the user interface for the detail item.
self.rateView.notSelectedImage = [UIImage imageNamed:@"shockedface2_empty.png"];
self.rateView.halfSelectedImage = [UIImage imageNamed:@"shockedface2_half.png"];
self.rateView.fullSelectedImage = [UIImage imageNamed:@"shockedface2_full.png"];
self.rateView.editable = YES;
self.rateView.maxRating = 5;
self.rateView.delegate = self;
if (self.detailItem) {
self.titleField.text = self.detailItem.data.title;
self.rateView.rating = self.detailItem.data.rating;
self.imageView.image = self.detailItem.fullImage;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self configureView];
}
- (void)viewDidUnload
{
[self setTitleField:nil];
[self setRateView:nil];
[self setImageView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)rateView:(RateView *)rateView ratingDidChange:(float)rating {
self.detailItem.data.rating = rating;
}
@end