mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 00:40:09 +00:00
(iOS) Don’t crash when closing an action sheet created by the RunActionSheet function.
This commit is contained in:
parent
c71a688d18
commit
9cbf7ed62a
@ -24,10 +24,11 @@
|
||||
/* buttons pulled from a RetroArch */
|
||||
/* string_list structure. */
|
||||
/*********************************************/
|
||||
static const void* const associated_delegate_key = &associated_delegate_key;
|
||||
|
||||
typedef void (^RAActionSheetCallback)(UIActionSheet*, NSInteger);
|
||||
|
||||
@interface RARunActionSheetDelegate : NSObject<UIActionSheetDelegate>
|
||||
@property (nonatomic, retain) RARunActionSheetDelegate* me;
|
||||
@property (nonatomic, copy) RAActionSheetCallback callbackBlock;
|
||||
@end
|
||||
|
||||
@ -36,10 +37,7 @@ typedef void (^RAActionSheetCallback)(UIActionSheet*, NSInteger);
|
||||
- (id)initWithCallbackBlock:(RAActionSheetCallback)callback
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
_me = self;
|
||||
_callbackBlock = callback;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -47,23 +45,25 @@ typedef void (^RAActionSheetCallback)(UIActionSheet*, NSInteger);
|
||||
{
|
||||
if (self.callbackBlock)
|
||||
self.callbackBlock(actionSheet, buttonIndex);
|
||||
self.me = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static void RunActionSheet(const char* title, const struct string_list* items, UIView* parent, RAActionSheetCallback callback)
|
||||
{
|
||||
RARunActionSheetDelegate* delegate = [[RARunActionSheetDelegate alloc] initWithCallbackBlock:callback];
|
||||
|
||||
UIActionSheet* actionSheet = [UIActionSheet new];
|
||||
actionSheet.title = BOXSTRING(title);
|
||||
actionSheet.delegate = (id)[[RARunActionSheetDelegate alloc] initWithCallbackBlock:callback];
|
||||
actionSheet.delegate = delegate;
|
||||
|
||||
for (int i = 0; i < items->size; i ++)
|
||||
{
|
||||
[actionSheet addButtonWithTitle:BOXSTRING(items->elems[i].data)];
|
||||
}
|
||||
|
||||
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
|
||||
|
||||
objc_setAssociatedObject(actionSheet, associated_delegate_key, delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
|
||||
[actionSheet showInView:parent];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user