ios - 将 UITableview 添加为 UIView 的 subview 时出现问题

标签 ios objective-c uitableview uiview

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

我有一个名为 Mapviewcontroller 的 View Controller 。

这个 Mapviewcontroller 由 map View 组成(全部使用 Storyboard创建)。单击 map 中的图钉时,我应该将 UIView 显示为 popupview(这是我自定义的 UIView,名为 mappopoverView)。

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

这个 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。任何人都可以帮我解决问题吗?如果我的问题令人困惑,抱歉。

最佳答案

您必须在 ma​​pviewcontroller 中创建 MappopoverViewma​​plocationtableview 的 IBOutlet,然后只需添加您的 ma​​plocationtableviewMappopoverView 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/

相关文章:

ios 检查 UITextfield.text 的数值是否大于 52

iphone - TableView Footer 随表格滚动

ios - 强制触摸 UITableViewCell 内部的 UICollectionView

ios - UITableView cellForRowAtIndexPath 中的 EXEC_BAD_ACCESS

ios - 使用 rxswift 禁用 UITableViewCell 编辑模式

objective-c - UIView 中的圆角

iOS Objective-C : How to increase number of rows after given condition

ios - 如何设计UIButton?

objective-c - 使用 AVPlayerLayer 作为 NSView 的支持层

objective-c - Objective-C : How to add Shadow effect to navigation bar and table cells