【发布时间】:2014-03-26 19:58:39
【问题描述】:
我有一个使用 CocoaPods 的项目,它很棒,直到我开始遇到一些问题。
我正在为 UIActionSheet 和 UIAlertView 使用一个带有块的 pod,这些块通过类别扩展了这些类。
我将 pod 添加到 .podsfile 并将标题导入到我的项目中。当我将代码添加到项目中时,Xcode 并没有抱怨什么,我什至在自动完成建议中看到了类别方法。
但是,当我运行该应用程序时,它总是在执行类别方法时崩溃,说“无法识别的选择器发送到(UIActionSheet 或UIAlertView)”。
我已将这些类直接添加到我的项目中,效果很好,所以我认为这是 CocoaPods 的问题。
这里以代码为例:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
RIButtonItem *selectPhotoButton = [RIButtonItem itemWithLabel:NSLocalizedString(@"Choose from library",nil) action:^{
[self selectPhoto];
}];
RIButtonItem *takePhotoButton = [RIButtonItem itemWithLabel:NSLocalizedString(@"Take a photo",nil) action:^{
[self takePhoto];
}];
UIActionSheet *ac = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Image source",nil) cancelButtonItem:[RIButtonItem itemWithLabel:NSLocalizedString(@"Cancel",nil)] destructiveButtonItem:nil otherButtonItems:takePhotoButton,selectPhotoButton, nil];
[ac showInView:self.view];
}
else
{
[self selectPhoto];
}
应用程序在 initWithTitle:cancelButtonItem:destructiveButtonItem:otherButtonItems 上崩溃
这是我的 Podsfile
pod 'MBProgressHUD'
pod 'Facebook-iOS-SDK'
pod 'UIAlertView-Blocks'
有什么想法吗?
【问题讨论】:
-
您可以发布您的
Podfile和一些导致您的应用程序崩溃的示例代码吗? -
添加示例,谢谢
-
好吧,我觉得不错。您是否在编辑完 podfile 后运行了
pod install并且正在使用.xcworkspace文件? -
还要确保您使用
#import <UIAlertView-Blocks/UIActionSheet+Blocks.h>导入 -
正如我所说 - Xcode 识别方法并且 eve 建议自动完成。谢谢