【问题标题】:ShareKit: Customizing text for different sharers (SHKActionSheet)ShareKit:为不同的共享者自定义文本(SHKActionSheet)
【发布时间】:2012-12-30 18:13:45
【问题描述】:

根据第2版的official FAQ根据用户选择的共享者自定义您的文本/内容,您需要:

  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: - 自定义机制 进程操作表的按下按钮被调用。

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

【问题讨论】:

    标签: objective-c subclass sharekit


    【解决方案1】:

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

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

    -(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];
    

    这对我来说没有问题。

    【讨论】:

      【解决方案2】:

      编辑:到目前为止,最好的方法是使用SHKShareItemDelegate。更多信息在ShareKit's FAQ

      【讨论】:

      • 感谢您在新年期间抽出时间回答;))请检查我的回答中的 upd1。正如您从我的代码中看到的那样,我从 SHKActionSheet 进行子类化(实际上我只是从文档中复制了它),但它仍然无法正常工作:(
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多