[英]Trouble in adding a UITableview as subview of UIView
Please help me to resolve this issue as I am struck up due to this issue. 由于这个问题让我感到震惊,请帮助我解决这个问题。
I have a view controller named Mapviewcontroller
. 我有一个名为
Mapviewcontroller
的视图控制器。
This Mapviewcontroller
consists of map view (all created using storyboard). 该
Mapviewcontroller
包含地图视图(全部使用情节Mapviewcontroller
创建)。 On click of the pins in the map, I should show a UIView
as a popupview
(This is my custom UIView
named mappopoverView
). 单击地图中的图钉时,我应该将
UIView
显示为popupview
(这是我的自定义UIView
名为mappopoverView
)。
This popoverview
should show some location lists too, so I used a UITableView
called maplocationTableview
. 这个
popoverview
应该显示一些位置列表,因此我使用了一个名为maplocationTableview
的UITableView
。
This maplocationtableview
I created & designed using storyboard in Mapviewcontroller
and initially set hidden. 我使用
Mapviewcontroller
情节maplocationtableview
创建和设计的Mapviewcontroller
最初设置为隐藏。 On click of map pins, I tried to add my tableview as subview but it is not working. 在单击地图图钉时,我尝试将表视图添加为子视图,但是它不起作用。
My code is: 我的代码是:
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];
But the tableview is not added as subview and also cellForRowAtIndexPath
is not invoked. 但是,不会将tableview添加为子视图,也不会调用
cellForRowAtIndexPath
。 Could any one please help me with a solution.Sorry if my question is confusing. 有人可以帮我解决一个问题,对不起,我的问题令人困惑。
You have to create IBOutlet of MappopoverView and your maplocationtableview in your mapviewcontroller and then you have to just add your maplocationtableview in MappopoverView outlet using addSubview also make sure you have IBOutlet mapview SO. 你在你的MapViewController创建MappopoverView的IBOutlet中,你的maplocationtableview,然后你必须只使用addSubview也确保你有IBOutlet中的MapView SO添加maplocationtableview在MappopoverView出口。 you have three IBOutlets now
您现在有三个IBOutlets
@property (strong, nonatomic) IBOutlet MKMapView *mapview;
@属性(强,非原子)IBOutlet MKMapView * mapview;
@property (strong, nonatomic) IBOutlet CUPopOverView *popoverview;
@属性(强,非原子)IBOutlet CUPopOverView * popoverview;
@property (strong, nonatomic) IBOutlet CUTableview *maplocationtableview;
@属性(强,非原子)IBOutlet CUTableview * maplocationtableview;
Please Go through following code: mapviewcontroller 请通过以下代码:mapviewcontroller
viewDidLoad 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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.