在这个链接中有关于 UIActivityViewController 如何工作的很好的信息:
http://www.aeth.com/iOSBook/ch26.html#_activity_view
基本上,您可以将 UIActivityViewController 子类化为另一个类并实现一个方法来知道它何时被解雇。
UIActivityViewController* avc =
[[UIActivityViewController alloc]
initWithActivityItems:@[myCoolString]
applicationActivities:@[[MyCoolActivity new]]];
下面是MyCoolActivity实现的准备部分:
-(NSString *)activityType {
return @"com.neuburg.matt.coolActivity"; // make up your own unique string
}
-(NSString *)activityTitle {
return @"Be Cool";
}
-(UIImage *)activityImage {
return self.image; // prepared beforehand
}
-(BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
for (id obj in activityItems) {
if ([obj isKindOfClass: [NSString class]])
return YES;
}
return NO;
}
-(void)prepareWithActivityItems:(NSArray *)activityItems {
self.items = activityItems;
}
为了执行该活动,我们实现了以下两种方法之一:
-(void)performActivity {
// ... do something with self.items here ...
[self activityDidFinish:YES];
}
-(UIViewController *)activityViewController {
MustacheViewController* mvc = [MustacheViewController new];
mvc.activity = self;
mvc.items = self.items;
return mvc;
}
然后 MustacheViewController 会有这样的代码:
- (IBAction)doCancel:(id)sender {
[self.activity activityDidFinish:NO];
}
- (IBAction)doDone:(id)sender {
[self.activity activityDidFinish:YES];
}