forked from tomcool420/SMFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMFInvocationCenteredMenuController.m
68 lines (64 loc) · 2.13 KB
/
SMFInvocationCenteredMenuController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// SMFInvocationCenteredMenuController.m
// SoftwareMenuFramework
//
// Created by Thomas Cool on 2/27/10.
// Copyright 2010 Thomas Cool. All rights reserved.
//
#import "SMFInvocationCenteredMenuController.h"
//#import "BRThemeInfo.h"
@implementation SMFInvocationCenteredMenuController
-(id)initWithTitles:(NSArray *)titles withInvocations:(NSArray *)invocations withTitle:(NSString *)title withDescription:(NSString *)description
{
self=[super init];
[self setListTitle:title];
[self setPrimaryInfoText:description];
int i,count=[titles count];
BRMenuItem *a;
for(i=0;i<count;i++)
{
a=[[BRMenuItem alloc] init];
[a setText:[titles objectAtIndex:i] withAttributes:[[BRThemeInfo sharedTheme]menuItemTextAttributes]];
[_items addObject:a];
[a release];
[_options addObject:[invocations objectAtIndex:i]];
}
return self;
}
-(void)itemSelected:(long)arg1
{
if([[_options objectAtIndex:arg1] respondsToSelector:@selector(invoke)])
[(NSInvocation *)[_options objectAtIndex:arg1]invoke];
[[self stack]popController];
}
+(NSInvocation *)invocationsForObject:(id)target withSelectorVal:(NSString *)selectorString withArguments:(NSArray *)arguments
{
if (selectorString==nil) {
return [[[NSInvocation alloc] init] autorelease];
}
SEL theSelector;
NSMethodSignature *aSignature;
NSInvocation *anInvocation;
id b = target;
theSelector = NSSelectorFromString(selectorString);
//theSelector= @selector(removeFromQueue:);
// NSLog(@"selector)
aSignature = [[target class] instanceMethodSignatureForSelector:theSelector];
//NSLog(@"signature: %@",aSignature);
anInvocation = [NSInvocation invocationWithMethodSignature:aSignature];
[anInvocation setSelector:theSelector];
[anInvocation setTarget:b];
if (arguments !=nil)
{
int i,count=[arguments count];
id c;
for(i=2;i<count+2;i++)
{
c=[arguments objectAtIndex:i-2];
[anInvocation setArgument:&c atIndex:i];
}
}
[anInvocation retainArguments];
return anInvocation;
}
@end