问题描述
我引用了一个使用代码创建界面而不是故事板文件的 IOS 项目.但是我的项目是使用故事板来构建用户界面.现在,我所有的文件都编译得很好,但就是不运行.我不断收到线程 1:信号 SIGABRT"错误.
I am referencing a IOS project that use code to create the interface rather than storyboard file.But my project is using storyboard to build the user interface.Right Now, all my file compile pretty well, but just do not run.I keep getting "Thread 1:signal SIGABRT" error.
以下是我的项目文件:
AppleDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "DetectionViewModel.h"
#import "ViewController.h"
#import "RscMgr.h"
@interface AppDelegate ()
@end
@implementation AppDelegate{
@private
UIWindow* _mainWindow;
RscMgr* _serialManager;
ViewController* _viewController;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_serialManager = [[RscMgr alloc] init];
DetectionViewModel* detectionViewModel = [[DetectionViewModel alloc] initWithSerialManager: _serialManager];
_viewController = [[ViewController alloc] initWithViewModel: detectionViewModel];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
ViewController.h
#import <UIKit/UIKit.h>
#import <opencv2/videoio/cap_ios.h>
#import <opencv2/imgcodecs/ios.h>
using namespace cv;
@class DetectionViewModel;
@interface ViewController : UIViewController<CvVideoCameraDelegate>{
IBOutlet UIImageView* imageView;
// IBOutlet UIButton* startButton;
CvVideoCamera* videoCamera;
}
@property (nonatomic, retain) CvVideoCamera* videoCamera;
//- (IBAction)startButton:(id)sender;
-(instancetype)initWithViewModel:(DetectionViewModel*)viewModel;
@end
ViewController.m
ViewController.m
#import "ViewController.h"
#import "DetectionViewModel.h"
#import "opencv2/videoio/cap_ios.h"
#import "opencv2/imgcodecs/ios.h"
@interface ViewController ()
@end
@implementation ViewController
{
@private
DetectionViewModel* _viewModel;
}
-(instancetype)initWithViewModel:(DetectionViewModel *)viewModel{
self = [super init];
if(self){
_viewModel = viewModel;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//serial Manager process
//
//camera
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate =self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset1920x1080;
// self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideo
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 20;
self.videoCamera.grayscaleMode = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Protocol CvVideoCameraDelegate
#ifdef __cplusplus
- (void)processImage:(cv::Mat &)image{
Mat imageCopy,imageCopy2,imageCopy3,imageCopy4;
cvtColor(image, imageCopy, COLOR_BGRA2BGR);//cvtColor(image, image, COLOR_BGR2GRAY);
cvtColor(imageCopy, imageCopy2, COLOR_BGR2HSV);//bitwise_not(imageCopy, imageCopy);
GaussianBlur(imageCopy2, imageCopy3, cv::Size(5,5),0, 0);//smooth the image with gaussian blur
cv::inRange(imageCopy3, cv::Scalar(100,127.5,28.05,1), cv::Scalar(131,255,137.7,1), imageCopy4);//recognize blue
// cv::inRange(imageCopy3, cv::Scalar(0,0,0,0), cv::Scalar(180,255,40,0), imageCopy4);//recognize black in HSV
//other:threshold(imageCopy, image, 0, 255, 0);
/*****************************find the contour of the detected area abd draw it***********************************/
//2-D point to store countour
std::vector< std::vector<cv::Point>> contour1;
int erosionSize = 3;//do opening on the binary thresholded image
Mat erodeElement = getStructuringElement(cv::MORPH_ELLIPSE,cv::Size(2*erosionSize+1,2* erosionSize+1), cv::Point(erosionSize,erosionSize));
erode(imageCopy4, imageCopy4, erodeElement);
dilate(imageCopy4, imageCopy4, erodeElement);
cv::findContours(imageCopy4, contour1, RETR_EXTERNAL, CHAIN_APPROX_NONE);//Acual line to find the contour
Scalar color1 = Scalar(50,50,50);//set the color used to draw the conotour
for(int i=0; i< contour1.size(); i++){//loop the contour to draw the contour
drawContours(image, contour1, i, color1);
}
/****************************find the contour of the detected area abd draw it***********************************/
/****************************Appproximate the contour to polygon && get bounded Rectangle and Circle*************/
std::vector<std::vector<cv::Point>> contours_poly(contour1.size());
std::vector<cv::Rect> boundedRect(contour1.size());
std::vector<cv::Point2f> circleCenter(contour1.size());
std::vector<float> circleRadius(contour1.size());
for (int i=0; i< contour1.size(); i++){
approxPolyDP(Mat(contour1[i]), contours_poly[i], 3, true);
boundedRect[i] = boundingRect(Mat(contours_poly[i]));
minEnclosingCircle((Mat)contours_poly[i], circleCenter[i], circleRadius[i]);
}
/*****************************draw the rectangle for detected area ***********************************************/
Scalar recColor = Scalar(121,200,60);
Scalar fontColor = Scalar(0,0,225);
int largestContourIndex=0;
for (int i=0; i<contour1.size(); i++){ //find the largest contour
if(boundedRect[i].area()> boundedRect[largestContourIndex].area())
largestContourIndex=i;
}
int j=largestContourIndex;
for (int i=0; i< 2/*contour1.size()*/; i++){ // draw all contours // draw Rect for the largest contour
if(contour1.size()>0){
if(boundedRect[j].area()>40){
rectangle(image, boundedRect[j].tl(), boundedRect[j].br(), recColor);
cv::Point fontPoint = boundedRect[j].tl();//show text at tr corner
putText(image, "Blue", fontPoint, FONT_HERSHEY_COMPLEX, 3, fontColor);
}
}
}
}
#endif
#pragma mark - UI Actions
- (IBAction)startVideoCamera:(UIBarButtonItem *)sender {
[self.videoCamera start];
}
- (IBAction)stopVideoCamera:(UIBarButtonItem *)sender {
[self.videoCamera stop];
}
- (IBAction)openWheel1:(UIBarButtonItem *)sender {
[_viewModel sendMessage:@"w1Open"];
}
- (IBAction)openWheel2:(UIBarButtonItem *)sender {
[_viewModel sendMessage:@"w2Open"];
}
@end
DetectionViewModel.h
#import <Foundation/Foundation.h>
@class RscMgr;
@interface DetectionViewModel : NSObject
-(instancetype)initWithSerialManager:(RscMgr*)serialManager;
-(void) sendMessage:(NSString*)message;
@end
DetectionViewModel.m
#import "DetectionViewModel.h"
#import "RscMgr.h"
@interface DetectionViewModel() <RscMgrDelegate>
@end
@implementation DetectionViewModel
{
@private
RscMgr* _serialManager;
}
-(instancetype)initWithSerialManager:(RscMgr* )serialManager{
self = [super init];
if(self){
_serialManager = serialManager;
[_serialManager setDelegate:self];
}
return self;
}
-(void)sendMessage:(NSString *)message{
[_serialManager writeString:message];
}
#pragma mark - Delegate
-(void)cableConnected:(NSString *)protocol{
}
-(void)cableDisconnected{
}
-(void)portStatusChanged{
}
-(void)readBytesAvailable:(UInt32)length{
}
@end
在控制台中:我有以下信息:2015-04-05 21:19:22.310 XRoverVideoProcessingTest[852:198728] * 由于未捕获的异常NSInvalidArgumentException"而终止应用程序,原因:在捆绑 NSBundle(已加载)中找不到名为Main"的故事板"* 先抛出调用栈:(0x184c2a530 0x195bac0e4 0x189a04484 0x1896c4590 0x1896c3728 0x1896c1f1c 0x18d0f1604 0x184be2d70 0x184be1e78 0x184be0078 0x184b0d1f4 0x1894a3020 0x18949e10c 0x10005fd68 0x19622aa08)libc++abi.dylib:以未捕获的 NSException 类型异常终止(lldb)
in Console:I have following info:2015-04-05 21:19:22.310 XRoverVideoProcessingTest[852:198728] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle (loaded)'* First throw call stack:(0x184c2a530 0x195bac0e4 0x189a04484 0x1896c4590 0x1896c3728 0x1896c1f1c 0x18d0f1604 0x184be2d70 0x184be1e78 0x184be0078 0x184b0d1f4 0x1894a3020 0x18949e10c 0x10005fd68 0x19622aa08)libc++abi.dylib: terminating with uncaught exception of type NSException(lldb)
And I did add the storyboard file name into the info list
推荐答案
在我看来,故事板文件可能没有添加到构建目标中,因此在启动时无法找到
It looks to me like perhaps the storyboard file was not added to the build target, so it can't be found at launch time
这篇关于IOS-将基于代码的界面转换为基于故事板的界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!