私はあなたの問題に直面し、おそらく最も美しいものではない解決策を見つけましたが、それは問題を解決します. SHKSharerDelegate と呼ばれるデリゲートがあり、この目的のために共有者と一緒に使用できます。そのため、共有者をコードから直接 (アクション シートなしで) 呼び出す場合は、次のようにする必要があります。
NSString* mySharerClassName = @"SHKFacebook";
SHKSharer* classItem = (SHKSharer*)[[NSClassFromString(mySharerClassName) alloc] init];
Class sharerClass = [classItem class];
if ( [sharerClass canShare] ){
[classItem performSelector: @selector(setItem:) withObject: item];
//Assuming that the class where this code is conforms to the SHKSharerDelegate protocol
[classItem performSelector: @selector(setShareDelegate:) withObject: self];
[classItem performSelector: @selector(send)];
}
ActionSheet を使用する必要がある場合は、ほとんどサポートされていないため、少し複雑になります。ActionSheet ヘッダー ファイル (ShareKit/UI/SHKActionSheet.h) に移動し、デリゲート プロパティを追加します。
@property (nonatomic, retain) id sharerDelegate;
そうではないことid<SHKSharerDelegate>
に注意してください。そうしようとすると、かなりの苦痛を経験するでしょう。だから私はそれが最も美しいものではないと言いました. プロパティを追加して合成したら、次のメソッドを探します。
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
そして、それが言うところ
id sharer = [sharers objectAtIndex:buttonIndex];
[NSClassFromString(sharer) performSelector:@selector(shareItem:) withObject:item];
変更してください
id sharer = [sharers objectAtIndex:buttonIndex];
if ( sharerDelegate == nil ){
[NSClassFromString(sharer) performSelector:@selector(shareItem:) withObject:item];
}else{
SHKSharer* classItem = [[NSClassFromString(sharer) alloc] init];
[classItem performSelector: @selector(setItem:) withObject: item];
[classItem performSelector: @selector(setShareDelegate:) withObject: sharerDelegate];
[classItem performSelector: @selector(send)];
}
これにもっと興味がある場合は、すぐにブログ投稿を作成し、回答を編集して参照できるようにします. 私はまだ誰かを助けることができることを願っています!