0

根据第 2 版的官方常见问题解答,根据用户选择的共享者自定义您的文本/内容,您需要:

  1. SHKActionSheet 的子类并覆盖dismissWithClickedButtonIndex
  2. 在配置器中设置新的子类名称(在 (Class)SHKActionSheetSubclass 中返回它;)。

它对我不起作用。但更重要的是:我把

NSLog(@"%@", NSStringFromSelector(_cmd));

在 (Class)SHKActionSheetSubclass 中查看它是否被调用。它不是 ;(( 所以 ShareKit 不关心这个配置选项......以前有人用过这个吗?

谢谢你!

UPD1:我在这里放了一些代码。 这是我的子类 ITPShareKitActionSheet 的样子。根据我需要覆盖的文档dismissWithClickedButtonIndex:animated:,但是为了跟踪我的类是否被调用,我还覆盖了actionSheetForItem:

+ (ITPShareKitActionSheet *)actionSheetForItem:(SHKItem *)item
{
    NSLog(@"%@", NSStringFromSelector(_cmd));

    ITPShareKitActionSheet *as = (ITPShareKitActionSheet *)[super actionSheetForItem:item];

    return as;
}

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animate
{
    NSLog(@"%@", NSStringFromSelector(_cmd));

    NSString *sharersName = [self buttonTitleAtIndex:buttonIndex];
    [self changeItemForService:sharersName];
    [super dismissWithClickedButtonIndex:buttonIndex animated:animate];
}

当用户按下“共享”按钮时,这是我在代码中创建操作表的操作:

- (IBAction)shareButtonPressed:(id)sender
{
    // Create the item to share
    SHKItem *item = [SHKItem text:@"test share text"];

    // Get the ShareKit action sheet
    ITPShareKitActionSheet *actionSheet = [ITPShareKitActionSheet actionSheetForItem:item];

    // Display the action sheet
    [actionSheet showInView:self.view]; // showFromToolbar:self.navigationController.toolbar];
}

当我运行此代码时,按“共享”按钮并选择我希望在日志中获得两行的任何共享者:

  1. actionSheetForItem:- 创建了自定义操作表
  2. dismissWithClickedButtonIndex:animated:- 处理操作表按下按钮的自定义机制被调用。

但由于某种原因,我只记录了第一行。

4

2 回答 2

0

编辑:到目前为止,实现这一目标的最佳方法是使用SHKShareItemDelegate. 更多信息在ShareKit 的 FAQ中。

于 2012-12-31T20:34:25.140 回答
0

我遇到了同样的问题,但我突然成功地调用了我的子类。

首先我的配置器是这样设置的:

-(Class) SHKActionSheetSubclass{
    return NSClassFromString(@"TBRSHKActionSheet");
}

现在我的子类:.h 文件

    #import "SHKActionSheet.h"
    @interface TBRSHKActionSheet : SHKActionSheet

    @end

.m 实现覆盖:

#import "TBRSHKActionSheet.h"
#import "SHKActionSheet.h"
#import "SHKShareMenu.h"
#import "SHK.h"
#import "SHKConfiguration.h"
#import "SHKSharer.h"
#import "SHKShareItemDelegate.h"

@implementation TBRSHKActionSheet

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
if (self) {
    // Initialization code
}
return self;
}

    + (SHKActionSheet *)actionSheetForItem:(SHKItem *)i
{
        NSLog(@"%@", NSStringFromSelector(_cmd));

    SHKActionSheet *as = [self actionSheetForType:i.shareType];
    as.item = i;
    return as;
}

     - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
{
   NSInteger numberOfSharers = (NSInteger) [sharers count];

    // Sharers
    if (buttonIndex >= 0 && buttonIndex < numberOfSharers)
    {
        bool doShare = YES;
        SHKSharer* sharer = [[NSClassFromString([sharers objectAtIndex:buttonIndex]) alloc] init];
        [sharer loadItem:item];
        if (shareDelegate != nil && [shareDelegate respondsToSelector:@selector(aboutToShareItem:withSharer:)])
        {
            doShare = [shareDelegate aboutToShareItem:item withSharer:sharer];
        }
        if(doShare)
            [sharer share];
    }

// More
else if ([SHKCONFIG(showActionSheetMoreButton) boolValue] && buttonIndex == numberOfSharers)
{
    SHKShareMenu *shareMenu = [[SHKCONFIG(SHKShareMenuSubclass) alloc] initWithStyle:UITableViewStyleGrouped];
    shareMenu.shareDelegate = shareDelegate;
    shareMenu.item = item;
    [[SHK currentHelper] showViewController:shareMenu];

}

[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}

最后,在我的实现文件中,我没有像 Vilem 建议的那样修改对 SHKActionSheet 的调用,因为某些依赖项似乎对我造成了冲突。

所以这是我的来电者(直接来自教程):

            NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];
    SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!" contentType:SHKURLContentTypeWebpage];

    // Get the ShareKit action sheet

    SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

    // ShareKit detects top view controller (the one intended to present ShareKit UI) automatically,
    // but sometimes it may not find one. To be safe, set it explicitly
    [SHK setRootViewController:self];

    // Display the action sheet
    [actionSheet showFromToolbar:self.navigationController.toolbar];

这对我来说没有问题。

于 2013-01-30T01:07:30.617 回答