不要忘了 Override isViewFromObject。
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
//
// CustomUITableView.m
//
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
//
// CustomUITableView.m
//
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
return YES;
}
// Need to override even perform nothing.
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
[pasteBoard setString:cell.textLabel.text];
}
}
//
// CustomUITableView.m
//
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIMenuItem *testMenuItem = [[UIMenuItem alloc] initWithTitle:@"Test" action:@selector(test:)];
[[UIMenuController sharedMenuController] setMenuItems: @[testMenuItem]];
[[UIMenuController sharedMenuController] update];
}
//
// CustomUITableViewCell.m
//
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{
NSLog(@"CustomTableViewCell: %@\n", NSStringFromSelector(action));
// There will be lots of default items if don't check.
if (action == @selector(copy:) || action == @selector(test:))
return YES;
return NO;
}
// It's said need to be overrode from forums, but test ok without overriding it.
//-(BOOL)canBecomeFirstResponder {
// return YES;
//}
/// this methods will be called for the cell menu items
-(void) test: (id) sender {
NSLog(@"CustomTableViewCell: test!");
}
// Classname.m
@interface Classname() {
id _instanceVar;
}
@property NSObject *extraProperty;
@end
// XYZPerson.h @interface XYZPerson : NSObject ... @property (readonly) NSString *uniqueIdentifier; - (void)assignUniqueIdentifier; @end // XYZPerson.m @interface XYZPerson () @property (readwrite) NSString *uniqueIdentifier; // readwrite 是 default 的屬性所以也可省略不寫 @end @implementation XYZPerson ... @end
NSString *const ALAssetPropertyType ; NSString *const ALAssetPropertyLocation ; NSString *const ALAssetPropertyDuration ; NSString *const ALAssetPropertyOrientation ; NSString *const ALAssetPropertyDate ; NSString *const ALAssetPropertyRepresentations ; NSString *const ALAssetPropertyURLs ; NSString *const ALAssetPropertyAssetURL;咦?怎麼沒有名稱 Name 呢?
ALAssetRepresentation *rep = [asset defaultRepresenttion]; [rep filename]; [rep size];
![]() |
| 圖1. Space Constraint |