I have one tableview with sections.First section there are 4开发者_JAVA百科 rows with label in it. In second and third section i have custom button.In fourth section i want to display mapview to display current location of user.does anyone have any idea how can i do it. Any tutorials or sample code?
You could create a custom UITableViewCell
(info) and add an MKMapView
to it. Then simply configure your map view and implement the MKMapView
delegate to respond to changes.
YOu need to set delegate & add mapView in the contentView of cell .
#import <MapKit/MapKit.h>
MKMapView *mapView;
NSString *locationStr;
MKAnnotationView *annotationView;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
if(indexPath.section ==3)
{
Initialize & alloc memory to Object of MKMapView
[cell.contentView addSubView:mapView]; //Add it to cells contentView
}
return cell;
}
To drop Annotation on MapView use this Delegate MEthod:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
// Use this method for placing custom Annotation in MapView
}
Hope this will solve your problem.
精彩评论