2011-07-26 3 views

답변

2

예! - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath (jQuery과의 대리자 메서드)

편집 내에서 (ani 컨트롤러 애니메이션할지 여부를 결정하는 BOOL입니다)
전화 [[UIMenuController sharedMenuController] setMenuVisible:YES animated:ani] 다음 UIMenuController의 '복사'명령은 기본적으로 detailTextLabel.text 텍스트를 복사하지 않습니다. 그러나 해결 방법이 있습니다. 클래스에 다음 코드를 추가하십시오.

-(void)copy:(id)sender { 
    [[UIPasteboard generalPasteboard] setString:detailTextLabel.text]; 
} 


- (BOOL)canPerformAction:(SEL)action withSender:(id)sender { 
    if(action == @selector(copy:)) { 
     return YES; 
    } 
    else { 
     return [super canPerformAction:action withSender:sender]; 
    } 
} 
+0

긴 꼭지를 사용해야합니다. –

+0

'tableView : didSelectRowAtIndexPath' 내부에 넣는다면, 보통의 방식으로 행을 선택할 때'UIMenuController'가 나타날 것입니다 (나는 이것이 당신이 원하는 것임을 모았습니다) – joshim5

+0

예, 아니오 :) COPY 옵션을 사용하여 메뉴를 가져 와서 ContactsTextLabel.text 텍스트를 가져와야합니다. 연락처 앱 –

9

에서 iOS 5에서는 간단한 방법은 UITableViewDelegate 방법을 구현하는 것입니다 :

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath 

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender 

- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender 

3 개 대표단을 구현함으로써, 길게 누르면 제스처 후 당신을 위해 UIMenuController를 호출 할 수있게된다. 예를 들면 다음과 같습니다.

/** 
allow UIMenuController to display menu 
*/ 
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 

/** 
allow only action copy 
*/ 
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender 
{ 
    return action == @selector(copy:); 
} 

/** 
if copy action selected, set as cell detail text 
*/ 
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender 
{ 
    if (action == @selector(copy:)) 
    { 
     UITableViewCell* cell = [tableView cellForIndexPath:indexPath]; 
     [[UIPasteboard generalPasteboard] setString:cell.detailTextLabel.text]; 
    } 
}