gpt4 book ai didi

ios - 从一个 viewController 调用方法,同时显示另一个 viewController

转载 作者:行者123 更新时间:2023-11-28 20:10:45 30 4
gpt4 key购买 nike

我有全屏 MapViewControllerLisViewController,它们显示在 popover 中。所以 ListViewController 是 TableView,我需要通过单击单元格来显示不同点的标注(以表格的行表示)。目前我无法解决这个问题..

在我的 listViewController 中我实现了

// LisViewController.h

@protocol ListViewControllerDelegate <NSObject>

- (void)showCalloutForObjectId:(id) objectId;

@end

@interface ListViewController : UITableViewController

@property (nonatomic, strong) id delegate;

@end

// ListViewController.m

- (id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder: aDecoder];
if (self) {
self.delegate = [MapViewController new]; // I BELIEVE THE PROBLEM IS HERE - CAN'T GET THE INSTANCE OF THE PRESENT VIEW CONTROLLER
}
return self;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary * data = [self.dataSet dataFromIndex: indexPath.row];
if ([self.delegate respondsToSelector:@selector(showCalloutForObjectId:)])
{
[self.delegate showCalloutForObjectId: data[@"object_id"]];
}
}

所以我的 MapViewController 中的方法从未被调用 - 有什么帮助吗?

最佳答案

您必须在 MapViewController 中分配 ListViewController 委托(delegate)属性

在实例化 ListViewController 后的 MapViewController 中:

ListViewController *lvc = [ListViewController alloc] init]; 
lvc.delegate = self;

当然你需要实现

-(void)showCalloutForObjectId:(id) objectId;

在你的 MapViewController

关于ios - 从一个 viewController 调用方法,同时显示另一个 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20367930/

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