UITableViewCell을 서브 클래스 화하는 대신 셀을 탭할 때 복사 메뉴를 구현하는 간단한 방법이 있습니까?UITableViewCell, 그룹화 된 스타일로 UIMenuController 표시
덕분에,
RL
UITableViewCell을 서브 클래스 화하는 대신 셀을 탭할 때 복사 메뉴를 구현하는 간단한 방법이 있습니까?UITableViewCell, 그룹화 된 스타일로 UIMenuController 표시
덕분에,
RL
예! - (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];
}
}
에서 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];
}
}
긴 꼭지를 사용해야합니다. –
'tableView : didSelectRowAtIndexPath' 내부에 넣는다면, 보통의 방식으로 행을 선택할 때'UIMenuController'가 나타날 것입니다 (나는 이것이 당신이 원하는 것임을 모았습니다) – joshim5
예, 아니오 :) COPY 옵션을 사용하여 메뉴를 가져 와서 ContactsTextLabel.text 텍스트를 가져와야합니다. 연락처 앱 –