2015-04-06 48 views
-4

我引用了一个使用代码创建界面而不是故事板文件的IOS项目。 但我的项目正在使用故事板来构建用户界面。 现在,我所有的文件都编译得很好,但是不运行。 我不断收到“线程1:信号SIGABRT”错误。IOS-基于代码的界面到基于Storyboard的界面

下面是我的项目文件:

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

#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',原因:'无法在包中找到名为'Main'的故事板NSBundle )” *第一掷调用堆栈: (0x184c2a530 0x195bac0e4 0x189a04484 0x1896c4590 0x1896c3728 0x1896c1f1c 0x18d0f1604 0x184be2d70 0x184be1e78 0x184be0078 0x184b0d1f4 0x1894a3020 0x18949e10​​c 0x10005fd68 0x19622aa08) 的libC++ abi.dylib:与类型NSException (LLDB)

的未捕获的异常终止
And I did add the storyboard file name into the info list 
+0

您是否在调试控制台或崩溃日志中看到更详细的消息? – 2015-04-06 02:05:00

+0

您是否将主要笔尖或故事板文件名添加到plist? – Jef 2015-04-06 02:08:38

+0

@Jef,对不起,延期见我的更新 – 2015-04-06 03:26:45

回答

0

它在我看来也许就像故事板fil e未添加到构建目标中,因此在启动时无法找到

+0

是的〜我查看了目标会员中的故事板后,它可以工作。 – 2015-04-06 16:01:54