实际上,我一直在研究如何从块中调用方法。我正在尝试从 iphone 照片应用程序中获取所有图像。这是代码....
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
if(group != nil) {
[self.groups addObject:group];
[group enumerateAssetsUsingBlock:selectionBlock];
}
};
[library enumerateGroupsWithTypes:groupTypes
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(@"A problem occurred");}];
在 selectionBlock ...我只想在用户单击任何图像时添加一个动作。所以我尝试了这段代码..
[imgView addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
buttonPressed 也在同一个 .m 文件中定义。
- (void) buttonPressed: (id) sender {
UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"Howdy!"
message:@"You tapped me."
delegate:nil
cancelButtonTitle:@"Cool"
otherButtonTitles:nil];
[av show];
}
但在 selectionBlock 我得到“没有可见的@interface for 'UIImageView' 声明选择器'addTarget:action:forControlEvents'”
我是 iOS 编程的新手。所以任何帮助都会非常非常感激!