IOS-Convert code-based interface to Storyboard based interface - ios

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

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

Related

Open CV Tutorial on IOS not working, EXC_BAD_ACCESS

I am trying to write a simple openCV app for iOS, but I am having trouble with using openCV functions in XCode. They will throw a EXC_BAD_ACCESS(code = 1), or not work entirely. I am using the processImage sample from the tutorial and that doesn't even work. I am using XCode 7.3 beta and believe I have installed openCV 2.4.11 correctly.
ViewController.h
#import <UIKit/UIKit.h>
#import <opencv2/highgui/cap_ios.h>
using namespace cv;
#interface ViewController : UIViewController <CvVideoCameraDelegate>
{
//IBOutlet UIImageView *imageView;
CvVideoCamera *camera;
}
#property (nonatomic, retain) CvVideoCamera* camera;
#end
ViewController.mm
#import "ViewController.h"
#import <opencv2/highgui/cap_ios.h>
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIImageView *imageView
#end
#implementation ViewController
#synthesize camera;
- (void)viewDidLoad {
[super viewDidLoad];
self.camera = [[CvVideoCamera alloc] initWithParentView: self.imageView];
self.camera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.camera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetHigh;
self.camera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.camera.defaultFPS = 60;
self.camera.grayscaleMode = NO;
self.camera.delegate = self;
self.camera.useAVCaptureVideoPreviewLayer = YES;
self.imageView.frame = self.view.bounds;
[self.camera start];
}
#pragma mark - Protocol CvVideoCameraDelegate
#ifdef __cplusplus
- (void)processImage:(cv::Mat&)image;
{
// Do some OpenCV stuff with the image
Mat image_copy;
cvtColor(image, image_copy, CV_BGRA2BGR);
// invert image
bitwise_not(image_copy, image_copy); // ERROR IS THROWN HERE, BUT IT
// WILL ALSO THROW ON THE CVTCOLOR
// IF I REMOVE THIS LINE
cvtColor(image_copy, image, CV_BGR2BGRA);
}
#endif
-(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
I don't see any problems in your code. Maybe try downloading the newest version of the framework from here. Note that the header file cap_ios.h has moved to videoio which means you'll have to import: Hope that helps
#import <opencv2/videoio/cap_ios.h>

Xcode error - unknown type name 'home'

this is my first question on stackoverflow.! Cheers.!
Please review my code from the link below. I have copy pasted appdelegate.h, appdelegate.m, viewcotroller.h&.m to a text document for reviewing purposes.
http://www.mediafire.com/view/85614p44t8eiqif/HomePageViewController.rtf
I will explain my problem in detail below.
I'm trying to recreate UICatalogue in a smaller scale all through code. I'm an app developement trainee. This is what I have done so far.
Keep in mind that my knowledge on Xcode and Objective-C is very limited. I'm using Xcode 5.1.1
I have created an instance variable (HPVC) for the Home Page view controller "HomePageViewController" in AppDelegate.h
I have set this HPVC as rootviewcontroller.
Declared and defined some instance variables.
*But I'm stuck in a loop from what I have searched so far.
I understand the importing has ended up in a loop. But I cant fix it.
Please check this and give me an answer. I can start my project If I can clear this obstacle.
Here is a screenshot of the error
http://www.mediafire.com/view/yjmwbb2dcb7rymd/Error.png
//
// AppDelegate.h
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "HomePageViewController.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
HomePageViewController *HPVC;
}
#property (strong, nonatomic) UIWindow *window;
#end
//
// AppDelegate.m
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
HPVC=[[HomePageViewController alloc]initWithNibName:#"HomePageViewController" bundle:nil];
self.window.rootViewController=HPVC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
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
//
// HomePageViewController.h
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface HomePageViewController : UIViewController
//Background Images for all the Views.
#property(nonatomic,strong) UIImageView *HomePageBG;
#property(nonatomic,strong) UIImageView *Page1ButtonBG;
#property(nonatomic,strong) UIImageView *Page2ControlsBG;
#property(nonatomic,strong) UIImageView *Page3TextFieldBG;
#property(nonatomic,strong) UIImageView *Page4TextView;
#property(nonatomic,strong) UIImageView *Page5Images;
#property(nonatomic,strong) UIImageView *Page6Segments;
#property(nonatomic,strong) UIImageView *Page7Toolbar;
#property(nonatomic,strong) UIImageView *Page8Alerts;
#property(nonatomic,strong) UIImageView *Page9Transitions;
//Home Page Elements.
#property(nonatomic,strong) UILabel *lblHomePageHeader;
#property(nonatomic,strong) UILabel *lblHomePageWelcome;
#property(nonatomic,strong) UIButton *BtnPage1;
#property(nonatomic,strong) UIButton *BtnPage2;
#property(nonatomic,strong) UIButton *BtnPage3;
#property(nonatomic,strong) UIButton *BtnPage4;
#property(nonatomic,strong) UIButton *BtnPage5;
#property(nonatomic,strong) UIButton *BtnPage6;
#property(nonatomic,strong) UIButton *BtnPage7;
#property(nonatomic,strong) UIButton *BtnPage8;
#property(nonatomic,strong) UIButton *BtnPage9;
#property(nonatomic,strong) UIButton *BtnChangeBGColor;
//Future Update. Add Button to change all button colors in Home Page.
#end
//
// HomePageViewController.m
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import "HomePageViewController.h"
#interface HomePageViewController ()
#end
#implementation HomePageViewController
#synthesize HomePageBG;
#synthesize Page1ButtonBG;
#synthesize Page2ControlsBG;
#synthesize Page3TextFieldBG;
#synthesize Page4TextView;
#synthesize Page5Images;
#synthesize Page6Segments;
#synthesize Page7Toolbar;
#synthesize Page8Alerts;
#synthesize Page9Transitions;
#synthesize lblHomePageHeader;
#synthesize lblHomePageWelcome;
#synthesize BtnPage1;
#synthesize BtnPage2;
#synthesize BtnPage3;
#synthesize BtnPage4;
#synthesize BtnPage5;
#synthesize BtnPage6;
#synthesize BtnPage7;
#synthesize BtnPage8;
#synthesize BtnPage9;
#synthesize BtnChangeBGColor;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//Home Page Background image added.
HomePageBG=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
HomePageBG.image=[UIImage imageNamed:#"Red"];
[self.view addSubview:HomePageBG];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
everything is correct but you forgot to import #import "HomePageViewController.h" on app delegate.m class

EXC_BAD_ACCESS error in Objective-C

I'm trying to write a simple iOS program that will notify when headphones are plugged/unplugged. I'm very new to Objective-C and iOS, and a lot of this code was written by somebody else and I'm now trying to adapt it so I'm having issues figuring out this problem. The code is here:
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
static void onHeadsetChange(void *, AudioServicesPropertyID, UInt32, const void *);
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.headsetOnHandler = self.headsetOffHandler = ^{};
NSLog(#"%lu", AudioSessionInitialize(NULL, NULL, NULL, NULL));
NSLog(#"%lu", AudioSessionSetActive(true));
NSLog(#"%lu", AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, &onHeadsetChange, (__bridge void *)self));
return YES;
}
static void onHeadsetChange(void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue) {
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
NSLog(#"The headset changed");
AppDelegate *const delegate = (__bridge AppDelegate *)inUserData;
const CFDictionaryRef routeChangeDictionary = inPropertyValue;
const CFNumberRef routeChangeReasonRef = CFDictionaryGetValue(routeChangeDictionary, CFSTR(kAudioSession_AudioRouteChangeKey_Reason));
SInt32 routeChangeReason;
CFNumberGetValue(routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
switch (routeChangeReason) {
case kAudioSessionRouteChangeReason_NewDeviceAvailable:
//NSLog([delegate description]);
[delegate headsetOnHandler];
break;
case kAudioSessionRouteChangeReason_OldDeviceUnavailable:
[delegate headsetOffHandler];
break;
default:
break;
}
}
#end
ViewController.m
#import "ViewController.h"
#implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
AppDelegate *delegate = (AppDelegate *)([UIApplication sharedApplication].delegate);
delegate.headsetOnHandler = ^{ self.view.backgroundColor = [UIColor greenColor];};
delegate.headsetOffHandler = ^{ self.view.backgroundColor = [UIColor redColor];};
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I'm getting the EXC_BAD_ACCESS error, code=1 at [delegate headsetOnHandler] and [delegate headsetOffHandler]. If I need to include the .h files for this to make sense, I will, and if there's anything else I'm missing please let me know.
EDIT:
I've added in declarations that people thought should be added:
#property (readwrite, assign) void (^headsetOnHandler)(void);
#property (readwrite, assign) void (^headsetOffHandler)(void);
How is the headsetOnHandler and headsetOffHandler properties declared?
If it is assign or retain, that is likely the source of your problem. Since they are blocks, it needs to be copy (even, in certain cases, under ARC). If they are atomic and retain, then your getter will call, effectively, [[block retain] autorelease] in the getter, which would explain your crash.
A bit of a long shot.
when you have a crash, always post the backtrace
when you know the line of code the crash is on, always post the variable declarations of any variables on that line
Note that ARC will change this behavior a bit, automatically handling the blocks in some cases, but -- IIRC -- you would still need to copy them in this case.

Compile Errors in untouched AppDelegate.m

I have been creating a simple example app to demonstrate playing sound files in IOS.
For this I have created a very simple XCode project with one view controller. However, although my AppDelegate.h and .m files have remained unedited I am getting strange parse issues in the AppDelegate.m.
On the line #Implimentation the compiler tells me its missing '#end'.
On the line -(BOOL) application: (UIApplication ) application didFinishLaunchingWithOptions: (NSDictionary) launch options it tells me Expected ';' after method prototype.
The issues seem to stem from the #import "ViewController.h" reference in the AppDelegate.m file. As when I remove this these two errors go away, and get replaced with Receiver 'ViewController' for class message is a forward declaration, which is what I would expect with a missing import.
This is an odd problem. I've built several IOS apps before but never encountered this issue. For background info the project was created as a Single View App in XCode 4. I have properly lined the IBOutlets and Properties of the ViewController.h to the XIB in interface builder. I have also added in the AudioToolbox framework in via the build phases > Link Library with Libraries feature.
Here is the delegete and view controller files files
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
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
AppDelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#end
ViewContoller.m
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#interface ViewController ()
SystemSoundID pig;
SystemSoundID cow;
SystemSoundID sheep;
SystemSoundID chicken;
#end
#implementation ViewController
#Synthesize but_cow, but_pig, but_sheep, but_chicken;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString * cowSoundURL= [[NSBundle mainBundle] pathForResource:#"cow" ofType: #"mp3"];
NSString * pigSoundURL= [[NSBundle mainBundle] pathForResource:#"pig" ofType: #"mp3"];
NSString * sheepSoundURL= [[NSBundle mainBundle] pathForResource:#"sheep" ofType: #"mp3"];
NSString * chiickenSoundURL= [[NSBundle mainBundle] pathForResource:#"chicken" ofType: #"mp3"];
AudioServicesCreateSystemSoundID(cowSoundURL, &cow);
AudioServicesCreateSystemSoundID(pigSoundURL, &pig);
AudioServicesCreateSystemSoundID( sheepSoundURL, &sheep);
AudioServicesCreateSystemSoundID(chickenSoundURL, &chicken);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//====================================================
/**
Called when a button is pressed
**/
//====================================================
-(IBAction)buttonPressed:(id)sender
{
if (sender == but_cow)
{
AudioServicesPlaySystem(cow);
}
else if (sender == but_sheep)
{
AudioServicesPlaySystem(sheep);
}
else if (sender == but_pig)
{
AudioServicesPlaySystem(pig);
}
else if (sender == but_chicken)
{
AudioServicesPlaySystem(chicken);
}
}//===================================================
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, retain) IBOutlet UIButton * but_cow;
#property (nonatomic, retain) IBOutlet UIButton * but_pig;
#property (nonatomic, retain) IBOutlet UIButton * but_sheep;
#property (nonatomic, retain) IBOutlet UIButton * but_chicken;
-(IBAction)buttonPressed:(id)sender;
Thanks very much for taking the time to read this.
ViewController.h seems to be missing an #end
The line:
#import "ViewController.h"
will basically copy in the entire file, so if there is an error in ViewController.h, it will show up everywhere that file is imported as well.
You are not adding #end in viewcontroller.h

Ios blank screen

So i am doing a simple app.I have to nib files.I change the nib that loads first from viewController to firstController but it only shoes a blank screen. Here is my code:
MyAppDelegate.h
#import <UIKit/UIKit.h>
#class IpadAppViewController,FirstPageViewController;
#interface IpadAppAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IpadAppViewController *viewController;
IBOutlet FirstPageViewController *firstController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet IpadAppViewController *viewController;
#property (nonatomic, retain) IBOutlet FirstPageViewController *firstController;
#end
MyAppDelegate.m
//
// IpadAppAppDelegate.m
// IpadApp
//
// Created by Stefan Andrei on 3/24/11.
// Copyright 2011 IMC. All rights reserved.
//
#import "IpadAppAppDelegate.h"
#import "IpadAppViewController.h"
#import "FirstPageViewController.h"
#implementation IpadAppAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize firstController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
[self.window addSubview:firstController.view];
[self.window makeKeyAndVisible];
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)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.
See also applicationDidEnterBackground:.
*/
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
Before doing [self.window addSubview:firstController.view], you should do
self.firstController = [[[FirstPageViewController alloc] initWithNibName:nil bundle:nil] autorelease];
If you've created FirstPageViewController together with the .xib, then that should be enough, otherwise you may need to pass the nib's name (without the .xib part) in initWithNibName:
Edit: added autorelease - the firstController property is retaining already.

Resources