【发布时间】:2012-04-16 12:15:14
【问题描述】:
我正在尝试将 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,但我不知道如何捕获该事件,或者即使这是正确的。我被卡住了。
任何帮助将不胜感激。
更新
正如评论所建议的,现在控制器位于一个类别上,使用操作表委托,可以在单击取消的操作表按钮时重新获得焦点。当操作完成或取消时,问题仍然存在。不知道如何捕捉该事件。
这是我的分类代码:
#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
【问题讨论】:
-
你有没有想过这个问题?我遇到了同样的问题:从 UIActionSheet 弹出框关闭可以正常工作,但完成一个动作(通过取消或成功完成)不会做任何事情。