繁体   English   中英

将UITableview添加为UIView的子视图时遇到问题

[英]Trouble in adding a UITableview as subview of UIView

由于这个问题让我感到震惊,请帮助我解决这个问题。

我有一个名为Mapviewcontroller的视图控制器。

Mapviewcontroller包含地图视图(全部使用情节Mapviewcontroller创建)。 单击地图中的图钉时,我应该将UIView显示为popupview (这是我的自定义UIView名为mappopoverView )。

这个popoverview应该显示一些位置列表,因此我使用了一个名为maplocationTableviewUITableView

我使用Mapviewcontroller情节maplocationtableview创建和设计的Mapviewcontroller最初设置为隐藏。 在单击地图图钉时,我尝试将表视图添加为子视图,但是它不起作用。

我的代码是:

  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添加为子视图,也不会调用cellForRowAtIndexPath 有人可以帮我解决一个问题,对不起,我的问题令人困惑。

你在你的MapViewController创建MappopoverView的IBOutlet中,你的maplocationtableview,然后你必须只使用addSubview也确保你有IBOutlet中的MapView SO添加maplocationtableviewMappopoverView出口。 您现在有三个IBOutlets

@属性(强,非原子)IBOutlet MKMapView * mapview;

@属性(强,非原子)IBOutlet CUPopOverView * popoverview;

@属性(强,非原子)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];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM