我正在尝试将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
答案 0 :(得分:0)
由于SHKActionSheet是UIActionSheet的子类,您可以将该类的委托设置为self,以了解何时解雇。
另外,[自我释放];在dealloc中完全误解了释放的作用,如果你处于dealloc然后释放自我将不会做任何事情! 了解内存管理规则。
我还应该警告你,[window addSubview:self.view]已被弃用,你根本不应该这样做。事实上,我没有看到包装共享工具包的理由,每个视图控制器应该能够轻松编写该代码。更糟糕的是,如果您不想每次都重写代码,可以将该代码放在UIViewController的类别中。