Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

objective c - IOS-Convert code-based interface to Storyboard based interface

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.

Below are my project file:

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

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...