2012-03-26 4 views
0

에서 텍스트를 가져 오는 이유는 무엇입니까? 코드가 작동하지 않는 이유를 모르겠지만 아무 것도 작동하지 않는 것 같습니다. 그래서 여기 도움을 청했습니다. 궁극적으로 "보기"버튼을 클릭 할 때마다 내 링크를 Safari에 보낼 수 있기를 원하며 "복사"버튼을 클릭 할 때마다 링크가 복사되기를 원합니다. 여기 NSMutableArray 테이블 뷰 셀

는 (아래에서 '- (보이드)의 viewDidLoad ") 코드이다 : 여기
NSMutableArray *sites = [[NSMutableArray alloc] initWithObjects:@"http://www.apple.com/", @"http://www.youtube.com/", @"http://maps.google.com/", @"http://ww.google.com/", @"http://www.stackoverflow.com/", nil]; 

self.cloudsendList = sites; 

코드이다 (아래의"- (IBAction를) touchUpInsideAction : 버튼 (있는 UIButton *) ")

NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell]; 

    NSUInteger index = [buttons indexOfObject:button]; 
    NSDictionary* buttonInfo = [buttonData objectAtIndex:index]; 

    if ([[buttonInfo objectForKey:@"title"] isEqualToString:@"View"]) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@", indexPath.row]]]; 

    } else if ([[buttonInfo objectForKey:@"title"]isEqualToString:@"Copy"]) { 
     NSString *message = indexPath.row; 
     [UIPasteboard generalPasteboard].string = message; 

참고로 각 셀의 NSMutableArray 데이터를 볼 수 있습니다. 단지 가져올 수 없습니다. 또한 "indexPath.row"대신 "cloudsendList indexPath.row"를 삽입하려고 시도했지만 작동하지 않았습니다. 나는 이것이 당신에게 충분한 정보를 제공하고 조금이라도 도움이되기를 바랍니다. 또한, 내가 노 보브 (noobish)라고 들으면 사과드립니다. 나는 여전히 Objective-C 프로그래밍에 익숙하다. 감사! :)

답변

1

indexPath.row는 해당 위치의 텍스트가 아닌 NSInteger입니다. 이것은 당신의 NSString * 메시지가 당신이있는 행의 정수 값을 얻는다는 것을 의미합니다 (0, 1, 2 ...). 사이트/cloudsendList 배열에서 가져올 때 해당 위치를 색인으로 사용해보십시오.

Ex.

NSString *message = [cloudsendList objectAtIndex:indexPath.row]; 

UPDATE :

는 브라우저를 열고 동일한 개념을 사용합니다.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@", [cloudsendList objectAtIndex:indexPath.row]]]]; 
+0

"[[UIApplication sharedApplication] openURL : [NSURL URLWithString : [NSString stringWithFormat :"? 나는 이것도 똑같이합니까? – chrisjr

+0

다른 예제로 업데이트되었습니다. 더 궁금한 점이 있으면 알려주세요. – Squatch

+0

대단히 감사합니다! 정말 감사. :) – chrisjr

관련 문제