ios - 关闭操作表时 ShareKit 失去焦点

标签 ios view focus sharekit

我正在尝试将 ShareKit 集成到我的 ios 游戏中。

一切正常,操作表已显示,我可以与之交互,但当 sharekit 操作完成时(通过关闭操作表或完成任何操作),我无法将焦点返回到我的应用程序。

我尝试了多种方法,但都对我有用。发生了什么? 我不是专业程序员,所以我想我遗漏了一些东西。

我是

这是我的.h

#import <UIKit/UIKit.h>
#import "SHK.h"
#import "SHKConfiguration.h"

@interface SocialWrapper: UIViewController{
}

- (id) init;
- (void) open;
- (void) dealloc;

@end

和.m

#import "SocializeWrapper.h"

@implementation SocialWrapper

- (id) init {
    self=[super init];

    DefaultSHKConfigurator *configurator = [[DefaultSHKConfigurator alloc] init];
    [SHKConfiguration sharedInstanceWithConfigurator:configurator];

    [SHK flushOfflineQueue];
    return self;
}

- (void) open
{  
    NSString *someText = @"Hello Earth!";
    SHKItem *item = [SHKItem text:someText];

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

    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self.view];

    [SHK setRootViewController:self];
    [actionSheet showInView:self.view];
}

- (void) dealloc {
     NSLog(@"SHK dealloc");
    [self release];
    [super dealloc];
}

@end

我使用这个包装器调用它

#import "SocializeWrapper.h"

SocialWrapper *socialize;

void SHKinit(void) {
    NSLog(@"SHK Init");    
    socialize = [[SocialWrapper alloc] init];  
}


void SHKopenWeb(void){
    NSLog(@"SHK Open actionsheet"); 
    [socialize open];
}

我正在使用 ios 5、xcode 4.3.2 和来自 git 的最新 sharekit 版本。

我想我必须在操作表关闭后关闭我的 SocialWrapper,但我不知道如何捕获该事件,或者即使这是正确的。我卡住了。

任何帮助将不胜感激。

更新

正如评论所建议的那样,现在 Controller 位于一个类别上,使用操作表委托(delegate),单击取消的操作表按钮时可以重新获得焦点。当操作完成或取消时,问题仍然存在。不知道如何捕获该事件。

这是我的类别代码:

#import "SocialWrapper.h"

@implementation UIViewController (SocialController)


-(void) loadconfig
{
    DefaultSHKConfigurator *configurator = [[DefaultSHKConfigurator alloc] init];
    [SHKConfiguration sharedInstanceWithConfigurator:configurator];

    [SHK flushOfflineQueue];
}

- (void) open
{  
    NSLog(@"Opening social button");  

    NSString *someText = @"Monkey Armada rules!";
    SHKItem *item = [SHKItem text:someText];

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

    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self.view];

    [actionSheet setDelegate:self];

    [SHK setRootViewController:self];
    [actionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
      NSLog(@"SHK actionsheet dissmiss with button %d", buttonIndex); 
     if(buttonIndex == 4)
     {
        NSLog(@"SHK close actionsheet");
        [self dismissViewControllerAnimated:YES completion:nil];
        [self.view removeFromSuperview];
     }
}
@end

最佳答案

既然 SHKActionSheet 是 UIActionSheet 的子类,您可以将该类的委托(delegate)设置为 self 以了解何时发生解雇。

此外,[ self 释放];在 dealloc 中完全误解了 release 的作用,如果你在 dealloc 中,那么释放 self 不会做任何事情! 了解内存管理规则。

我还应该警告您 [window addSubview:self.view] 已被弃用,您根本不应该这样做。事实上,我看不出有什么理由将共享工具包的东西包装起来,每个 View Controller 都应该能够轻松地编写该代码。更糟糕的是,如果您不想每次都重写代码,您可以将该代码放在 UIViewController 的一个类别中。

关于ios - 关闭操作表时 ShareKit 失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10173871/

相关文章:

python - 在 Django 的 html 页面中渲染多个查询集

CSS 焦点最后一个 child

WPF,ListBox的ItemTemplate有CheckBox,但是CheckBox好像不是item

ios - 通用 iOS 应用程序文件管理

ios - UITableView 在上方和下方添加空行,在将页眉和页脚设置为空 View 后仍然存在

iphone - 如何将文件下载到 iPhone 的文件系统?

javascript - CSS::contenteditable 中元素的焦点

iphone - 如何将 exif 元数据写入图像(不是相机胶卷,只是 UIImage 或 JPEG)

ruby-on-rails - 未定义方法 `each' 为 nil :NilClass?

grails - grails gson View 使用模板扩展子项