请帮助我解决这个问题,因为这个问题让我感到震惊。
我有一个名为 Mapviewcontroller
的 View Controller 。
这个 Mapviewcontroller
由 map View 组成(全部使用 Storyboard创建)。单击 map 中的图钉时,我应该将 UIView
显示为 popupview
(这是我自定义的 UIView
,名为 mappopoverView
)。
这个 popoverview
也应该显示一些位置列表,所以我使用了一个名为 maplocationTableview
的 UITableView
。
这个 maplocationtableview
我在 Mapviewcontroller
中使用 Storyboard创建和设计,最初设置为隐藏。单击 map 图钉时,我尝试将我的表格 View 添加为 subview ,但它不起作用。
我的代码是:
self. maplocationtableview.hidden = NO;
MappopoverView *alertView = [[MappopoverView alloc] initTableview:self.maplocationtableview];
alertView.delegate = self;
[alertView show];
[self. maplocationtableview setDelegate:self];
[self. maplocationtableview setDatasource:self];
[self. maplocationtableview reloadData];
但是 tableview 没有添加为 subview ,也没有调用 cellForRowAtIndexPath
。任何人都可以帮我解决问题吗?如果我的问题令人困惑,抱歉。
最佳答案
您必须在 mapviewcontroller 中创建 MappopoverView 和 maplocationtableview 的 IBOutlet,然后只需添加您的 maplocationtableview 在 MappopoverView socket 中使用 addSubview 还要确保你有 IBOutlet mapview SO。你现在有三个 IBOutlets
@property (strong, nonatomic) IBOutlet MKMapView *mapview;
@property (strong, nonatomic) IBOutlet CUPopOverView *popoverview;
@property (strong, nonatomic) IBOutlet CUTableview *maplocationtableview;
请通过以下代码:mapviewcontroller
viewDidLoad
self.mapview.delegate = self;
[self.mapview setShowsUserLocation:YES];
[self.popoverview addSubview:self.maplocationtableview];
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
if(![self.popoverview isDescendantOfView:view])
[view addSubview:self.popoverview];
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = CLLocationCoordinate2DMake(LAT, LONG);
[self.mapview addAnnotation:point];
}
关于ios - 将 UITableview 添加为 UIView 的 subview 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25080654/