2012-12-04 4 views
1

코드가 있습니다. 그건 그렇고, 나는 전화를받을 수 없으며 웹 사이트도 열리지 않습니다!정적 셀을 Outlet/Actions에 연결하는 방법 - E.G 번호로 전화를 걸려면 호출 셀을 누릅니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSString *urlToOpen = @""; 
if(indexPath.section == 0){ 
    // call number 
    urlToOpen = @"tel:442074036933"; 
} else if(indexPath.section == 1){ 
    // open website 
    urlToOpen = @"http://www.designmuseum.org"; 
} else { 
    // open address 

    urlToOpen = @"http://maps.apple.com/maps?daddr=Design+Museum+London"; 
} 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlToOpen]]; 
NSString *destinationAddress = [NSString stringWithFormat:@"%@+%@+%@", 
           [address street], 
           [address city], 
           [address country]]; 

NSString *sourceAddress = [LocalizedCurrentLocation currentLocationStringForCurrentLanguage]; 

NSString *url = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%@&daddr=%@", 
       [sourceAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], 
       [destinationAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; 

내 응용 프로그램의 대상 주소를 추가해야합니다. 28 Shad Thames, London, United Kingdom. 어떤 형식으로 쓸 수 있습니까? 왜냐하면 내가 일을 할 수 없어 정말 내 애플 리케이션 의이 문제를 신속하게 정렬해야합니다.

답변

1

각 셀마다 콘센트를 만들 필요는 없습니다.

didSelectRowAtIndexPath 메서드가 호출 되었습니까?

그런 다음 당신은 다만 수 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *urlToOpen = @""; 
    if(indexPath.section == 0){ 
     // call number 
     urlToOpen = @"tel:12125551212"; 
    } else if(indexPath.section == 1){ 
     // open website 
     urlToOpen = @"http://www.google.nl"; 
    } else { 
     // open address 
      NSString *destinationAddress = @"Amsterdam"; 

      Class itemClass = [MKMapItem class]; 
      if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { 

       CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
       [geocoder geocodeAddressString:destinationAddress completionHandler:^(NSArray *placemarks, NSError *error) { 
        if([placemarks count] > 0) { 

         MKPlacemark *placeMark = [[MKPlacemark alloc] initWithPlacemark:[placemarks objectAtIndex:0]]; 

         MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placeMark]; 

         MKMapItem *mapItem2 = [MKMapItem mapItemForCurrentLocation]; 


         NSArray *mapItems = @[mapItem, mapItem2]; 

         NSDictionary *options = @{ 
             MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, 
             MKLaunchOptionsMapTypeKey: 
             [NSNumber numberWithInteger:MKMapTypeStandard], 
             MKLaunchOptionsShowsTrafficKey:@YES 
         }; 

         [MKMapItem openMapsWithItems:mapItems launchOptions:options]; 

        } else { 
         //error nothing found 
        } 
       }]; 
       return; 
      } else { 

       NSString *sourceAddress = [LocalizedCurrentLocation currentLocationStringForCurrentLanguage]; 

       urlToOpen = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@&daddr=%@", 
          [sourceAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], 
          [destinationAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
      } 
    } 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlToOpen]]; 
} 

indexPath.section은 또한 당신이있는 tableView를 만든 방법에 따라, indexPath.row 수 있습니다.

편집 : '길 찾기'부분을 추가했습니다. ios5 또는 ios6인지 확인합니다.

는 iOS5를 위해 나는 내가 장소를 취득하고 그것으로지도와 현재 위치를 엽니 다 CLGeocoder를 사용 iOS6의 경우이 게시물 http://www.martip.net/blog/localized-current-location-string-for-iphone-apps

에서 LocalizedCurrentLocation를 사용합니다.

내 응용 프로그램 자체에서 할 것이 아니라 발사 할 수있는 방법이 없다,이 구현은,지도 응용 프로그램을 엽니 다

+0

내가 불행하게도, 1 개 마지막 질문을 해달라고 15 평판 필요 CoreLocation.framework 및 MapKit.framework 추가해야합니다 지도 앱 – holtii

+0

가능하지만 '길 찾기'부분을 만들 수 없습니다. 선과 탐색 등을 사용하지 않고 위치와 목적지 만 표시 할 수 있습니다. mapView를 만들어야합니다. http://prassan-warrior.blogspot.dk/2012/11/apple-maps-on-iphone-with-mapkit-and.html –

+0

자습서가 있습니다. 비슷한 앱이 있는데, 내 탭 중 1 개는 'design museum london'에 장소 표시를 보여주는 공개 버튼이 있습니다. 동일한 것을 구현하고 싶었던지도 앱은 정보를 표시하고 방향 버튼을 표시하지만 내 앱의지도 뷰 내에서 모든 것을 원했습니다. – holtii