Ios 无法通过遍历字典自动创建UIAlertAction obj
我发现为我的Ios 无法通过遍历字典自动创建UIAlertAction obj,ios,objective-c,dictionary,block,traversal,Ios,Objective C,Dictionary,Block,Traversal,我发现为我的UIAlertController创建每个UIAlertAction的工作太多了,所以我尝试使用字典及其键来创建所有操作,但没有成功 这是我的字典: - (NSDictionary *)inputActions { static NSDictionary *actions = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ actions = @{@
UIAlertController
创建每个UIAlertAction
的工作太多了,所以我尝试使用字典及其键来创建所有操作,但没有成功
这是我的字典:
- (NSDictionary *)inputActions
{
static NSDictionary *actions = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
actions = @{@(BLGradeTypeGPA): @"GPA",
@(BLGradeTypeGRE): @"GRE",
@(BLGradeTypeIELTS): @"IELTS",
@(BLGradeTypeSAT): @"SAT",
@(BLGradeTypeSSAT): @"SSAT",
@(BLGradeTypeTOEFL): @"TOEFL",
@(BLGradeTypeGMAT): @"GMAT"};
});
return actions;
}
我把动作编码在这里:
[inputActions enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop)
{
NSString *title = [inputActions valueForKey:key];
UIAlertAction *inputAction = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
{
NSNumber *num = key;
BLGradeType type = num.integerValue;
if ([weakSelf checkDuplicateWithGradeType:type])
{
[weakSelf loadDuplicatGradeTypeAlert];
}
else
{
[weakSelf gradeTypeSelectedForGradeCell:cell withGradeType:type];
}
}];
[ac addAction:inputAction];
}];
但是,当我触发相关方法以显示UIAlertController
时,它将生成以下错误:
[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000003
(null)
((
0 CoreFoundation 0x000000018269ee50 <redacted> + 148
1 libobjc.A.dylib 0x0000000181d03f80 objc_exception_throw + 56
2 CoreFoundation 0x00000001826a5ccc <redacted> + 0
3 CoreFoundation 0x00000001826a2c74 <redacted> + 872
4 CoreFoundation 0x00000001825a0d1c _CF_forwarding_prep_0 + 92
5 Foundation 0x0000000182f91f94 <redacted> + 44
6 BankwelLiuxue 0x00000001002a2a84 __72-[BLGradeInputViewController loadGradeOptionAlertSheetForGradeTypeCell:]_block_invoke + 112
7 CoreFoundation 0x00000001825ea50c <redacted> + 88
8 CoreFoundation 0x00000001825d8184 <redacted> + 180
9 BankwelLiuxue 0x00000001002a2898 -[BLGradeInputViewController loadGradeOptionAlertSheetForGradeTypeCell:] + 364
10 BankwelLiuxue 0x00000001002a3e08 -[BLGradeInputViewController gradeInputTableViewCell:didTapGradeType:] + 104
11 BankwelLiuxue 0x00000001002ebb50 -[BLGradeInputTableViewCell gradeTypeLabelTapped:] + 104
12 UIKit 0x0000000187d79c8c <redacted> + 164
13 UIKit 0x000000018798e5dc <redacted> + 172
14 UIKit 0x000000018781b688 <redacted> + 784
15 UIKit 0x0000000187d7b28c <redacted> + 72
16 UIKit 0x00000001877da3d8 <redacted> + 372
17 UIKit 0x00000001877d7154 <redacted> + 2404
18 UIKit 0x00000001878194f8 <redacted> + 1132
19 UIKit 0x0000000187818af4 <redacted> + 764
20 UIKit 0x00000001877e8f4c <redacted> + 248
21 UIKit 0x00000001877e7528 <redacted> + 6568
22 CoreFoundation 0x0000000182655124 <redacted> + 24
23 CoreFoundation 0x0000000182654bb8 <redacted> + 540
24 CoreFoundation 0x00000001826528b8 <redacted> + 724
25 CoreFoundation 0x000000018257cd10 CFRunLoopRunSpecific + 384
26 GraphicsServices 0x0000000183e64088 GSEventRunModal + 180
27 UIKit 0x0000000187851f70 UIApplicationMain + 204
28 BankwelLiuxue 0x0000000100294eec main + 124
29 libdyld.dylib 0x000000018211a8b8 <redacted> + 4
)
但是它没有进入处理程序块,而是崩溃了。它给出错误的是哪一行?@Shubhank它能够转到这一行
UIAlertAction*inputAction=[UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction*\u Nonnull action)
但无法进入块部分并崩溃。[weakSelf checkDuplicateWithGradeType:type]它包含什么?@PKT我可以将代码粘贴到这里,但您认为它相关吗?因为程序似乎无法到达该代码行。它只是调用另一个UIAlertController
,警告您选择了重复选项。根据我的思考错误,您正在尝试获取整数对象的长度不允许这样做,所以在xcode中搜索长度键盘,并尝试在所有异常断点下调试它给出错误的那一行?@Shubhank它能够转到这一行UIAlertAction*inputAction=[UIAlertAction actionWithTitle:title样式:UIAlertActionStyleDefault处理程序:^(UIAlertAction*\U非空操作)
但无法进入块部分并崩溃。[weakSelf checkDuplicateWithGradeType:type]它包含什么?@PKT我可以将代码粘贴到这里,但您认为它相关吗?因为程序似乎无法到达该代码行。它只是调用另一个UIAlertController
,警告您选择了重复选项。根据我的思考错误,您正在尝试获取整数对象的长度这是不允许的,所以在xcode中搜索长度键盘,并尝试使用所有异常断点进行调试
UIAlertAction *inputAction = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)