SMS
SMS

Reputation: 558

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.

This Mapviewcontroller consists of map view (all created using storyboard). On click of the pins in the map, I should show a UIView as a popupview (This is my custom UIView named mappopoverView).

This popoverview should show some location lists too, so I used a UITableView called maplocationTableview.

This maplocationtableview I created & designed using storyboard in Mapviewcontroller and initially set hidden. 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. Could any one please help me with a solution.Sorry if my question is confusing.

Upvotes: 0

Views: 243

Answers (1)

Jasmin
Jasmin

Reputation: 794

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. you have three IBOutlets now

@property (strong, nonatomic) IBOutlet MKMapView *mapview;

@property (strong, nonatomic) IBOutlet CUPopOverView *popoverview;

@property (strong, nonatomic) IBOutlet CUTableview *maplocationtableview;

Please Go through following code: 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];
}

Upvotes: 1

Related Questions