2011-03-22 62 views
0

我有一個tableview與章節。第一節有4行與標籤在其中。 在第二和第三部分我有自定義按鈕。第四部分我想顯示 mapview來顯示user.does的當前位置任何人有任何想法我該怎麼做。 任何教程或示例代碼?如何在tableview單元格中顯示mapview的分段?

回答

0

您可以創建自定義UITableViewCellinfo),併爲其添加MKMapView。然後只需配置您的地圖視圖並實施MKMapViewdelegate以對變化做出響應。

+0

] mapView = [[MKMapView alloc] initWithFrame:frame22]; \t \t \t mapView.mapType = MKMapTypeStandard; \t \t \t CLLocationCoordinate2D location = mapView.userLocation.coordinate; \t \t \t MKCoordinateSpan span; \t \t \t MKCoordinateRegion region; \t \t \t \t \t \t location.latitude = [[aVolunteer latitude] floatValue]; \t \t \t location.longitude = [[aVolunteer longitude] floatValue]; \t \t \t mapView.scrollEnabled = YES; \t \t \t span.latitudeDelta = 0.05; \t \t \t span.longitudeDelta = 0.05; – nehal 2011-03-23 12:04:22

0

YOu需要設置代理&在cellView的contentView中添加mapView。

#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; 
    } 

要在MapView。使用該委託的方法降譯註:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 

// Use this method for placing custom Annotation in MapView 

} 

希望這將解決您的問題。

+0

我已經通過插入以下代碼解決了這個問題:mapView = [[MKMapView alloc] initWithFrame:frame22]; \t \t \t mapView.mapType = MKMapTypeStandard; \t \t \t CLLocationCoordinate2D location = mapView.userLocation.coordinate; \t \t \t MKCoordinateSpan span; \t \t \t MKCoordinateRegion region; \t \t \t \t \t \t location.latitude = [[aVolunteer latitude] floatValue]; \t \t \t location.longitude = [[aVolunteer longitude] floatValue]; \t \t \t mapView.scrollEnabled = YES; \t \t \t span.latitudeDelta = 0.05; \t \t \t span.longitudeDelta = 0。05; – nehal 2011-03-23 12:05:17

+0

你是否已經在mapView中使用了mapView中的單元格或任何其他方式?因爲你應該在UITableView中使用它;;) – 2011-03-23 13:20:32

+0

我已經聲明瞭子視圖像這樣UIView * subView = [[UIView alloc] initWithFrame: CGRectMake(10,0,300,45)]; 然後在第4部分 情況3: \t \t \t subView.backgroundColor = [UIColor whiteColor]; [subView insertSubview:[self loadMap] atIndex:0]; cell1.backgroundView = subView; [subView release]; 然後在loadmap函數中寫上面的註釋代碼 – nehal 2011-04-13 13:16:01

相關問題