gpt4 book ai didi

ios - prepareForSegue : object

转载 作者:行者123 更新时间:2023-11-29 13:30:53 25 4
gpt4 key购买 nike

我的应用有核心数据和两个 View CoursesTableViewController 和 DetailViewController。

如果用户点击 Detail Disclosure 按钮转到 DetailViewController 以显示一些细节。

应用使用 didSelectRowAtIndexPath 和 didDeselectRowAtIndexPath 做其他事情。

CoursesTableViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];

}

}

DetailViewController.h

@property (strong, nonatomic) id detailItem;

@property (weak, nonatomic) IBOutlet UITextField *courseCodeLabel;
@property (weak, nonatomic) IBOutlet UITextField *courseNameLabel;

DetailViewController.m

@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

@synthesize detailItem = _detailItem;
@synthesize courseCodeLabel = _courseCodeLabel;
@synthesize courseNameLabel = _courseNameLabel;


#pragma mark - Managing the detail item



- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;

// Update the view.
[self configureView];
}
}

- (void)configureView
{
// Update the user interface for the detail item.

if (self.detailItem) {
self.courseCodeLabel.text = [[self.detailItem valueForKey:@"courseCode"] description];
self.courseNameLabel.text = [[self.detailItem valueForKey:@"courseName"] description];

}
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
self.courseCodeLabel = nil;
self.courseNameLabel = nil;

}

问题是当我点击 Detail Disclosure 时,segue 运行良好,但在 DetailViewController 中,courseCodeLabel 和 courseNameLabel 中没有任何值。

最佳答案

导入并尝试转换目标 View Controller 。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];

DetailViewController * detailVC = (DetailViewController *)[segue destinationViewController];

[detailVC setDetailItem:object];

}

}

关于ios - prepareForSegue : object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11935745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com