IPAD must-haves. And fun-to-haves.

Brighten your iPad with a colorful cover, stream to your TV, download pictures from your digital camera, and more. There’s already so much you can do with iPad and iPad mini

Apple Wireless Keyboard

The incredibly thin Apple Wireless Keyboard uses Bluetooth technology, which makes it compatible with iPad

Apple unveils iPad mini: ‘Thin as a pencil, light as paper’

iPad inspires creativity and hands-on learning with features you won’t find in any other educational tool

Lightning connector and FaceTime HD camera

Apple announces 4th generation iPad packing an A6X CPU

Pages

Showing posts with label cocoa. Show all posts
Showing posts with label cocoa. Show all posts

Sunday, April 7, 2013

Beginning cocoa programming: delegates

Xcode 3.2.2

Mac OS X 10.6.8

Cocoa Programming for Mac OS X (third edition)

Chapter 6: Helper objects

 

What happened to the forum software?  I can't quote text/code anymore.

 

I'm trying to create a simple delegate for an NSWindow.  The delegate implements this method:

 

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;

 

I can get my delegate to work if I use Interface Builder to connect my app's main(and only) window to an instance of my object(which appears in the MainMenu.xib inspector in IB).  However, I cannot get a delegate to work if I call setDelegate: on my app's main window.  In the book, there is one example where they use setDelegate: to setup the delegate object.  There is another example where they use IB to hook up the delegate.  The only distinction I can detect between the two examples is that in the one that employs setDelegate:, the delegate-or is not a widget, and in the one that uses IB to make the connection, the delegate-or is a widget.

 

This is the code that I used to try and programmatically set up a delegate:

 

//AppController.h

 

#import

 

@interface AppController : NSObject {

 

  IBOutlet NSWindow* window;

}

- (id)init;

 

 

@end

 

 

 

//AppController.m

 

#import "AppController.h"

#import "MyDelegate.h"

 

@implementation AppController

 

- (id)init

{

 

  if (![super init]) {

  return nil;

  }

 

  MyDelegate* aDelegate = [[MyDelegate alloc] init];

  [window setDelegate:aDelegate];

 

  return self;

}

 

 

@end


 

 

 

//MyDelegate.h

 

#import

 

@interface MyDelegate : NSObject {

 

}

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;

 

 

@end

 

 

 

//MyDelegate.m

 

#import "MyDelegate.h"

 

 

@implementation MyDelegate

 

 

- (NSSize)windowWillResize:(NSWindow *)sender

                         toSize:(NSSize)frameSize

{

     frameSize.height = 2 * frameSize.width;

     return frameSize;

}

 

 

@end


 

 

In IB, I went into the Library, and I dragged an Object to the MainMenu.xib window/inspector, and I named it AppController.  Then I dragged a connection from the AppController outlet named 'window' to the NSWindow.  When I build&run my code, I can resize the window to any size--the window size is not constrained to a 2:1 ratio. That is not the result I expect: I expect the window size to maintain a 2:1 ration. If I set an object's delegate, then when the event occurs, the object should grab the delegate and use it to call the delegation methods; there is nothing more I should have to do in my code.  What am I not understanding about cocoa delegates?


View the original article here

Re: Beginning cocoa programming: delegates

I constructed another simple example of a delegate: I created an app with one lone NSTextField on the window.  I wanted to see if setDelegate: would work with a different widget(NSTextField v. NSWindow).  My goal was to see if I could setup a delegate using setDelegate: on an NSTextField, such that a delegate method would be called when I typed in the text field.  I  looked through the documentation, and I decided to to see if implementing this delegate method would work:

 

- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor;

 

 

I created a new app(deleting the classes that Xcode automatically creates, as well as the instance in the MainWindow.xib window in IB), and then I created this class:

 

 

//MyDelegate.h

 

import

 

@interface MyDelegate : NSObject {

}

- (BOOL)control:(NSControl *)control

          textShouldBeginEditing:(NSText *)fieldEditor;

 

@end

 

 

//MyDelegate.m

 

@implementation MyDelegate

 

- (BOOL)control:(NSControl *)control

               textShouldBeginEditing:(NSText *)fieldEditor

{

          NSLog(@"***In delegate method...");

          return YES;

}

 

@end

 

 

1) In IB, I created an instance of MyDelegate by dragging an Object from the Library onto the MainWindow.xib window.  I entered the name MyDelegate in the TextField Identity Inspector.

 

2) In IB, I ctrl-clicked on the NSTextField, and then I dragged a connection from NSTextField's 'delegate' outlet to the MyDelegate instance(in the MainWindow.xib window).

 

3) Saved everything, build&run, and when I typed in the text field, I saw the logged message in the Debugger Console, as expected.

 

Next, I attempted to create code that uses setDelegate: to achieve the same thing as above.

 

4) In IB, I ctrl-clicked on the NSTextField and deleted the connection from the 'delegate' outlet to the MyDelegate instance.

 

5)  I made these changes to the code:

 

//MyDelegate.h

 

#import

 

@interface MyDelegate : NSObject {

 

          IBOutlet NSTextField* textField;

}

- (id)init;

- (BOOL)control:(NSControl *)control

          textShouldBeginEditing:(NSText *)fieldEditor;

 

@end

 

 

//MyDelegate.m

#import "MyDelegate.h"

 

@implementation MyDelegate

 

- (id) init

{

          if (![super init]) {

                    return nil;

          }

 

          [textField setDelegate:self];

 

          return self;

}

 

- (BOOL)control:(NSControl *)control

          textShouldBeginEditing:(NSText *)fieldEditor

{

          NSLog(@"***In delegate method...");

          return YES;

}

 

@end

 

 

6) In IB, I ctrl-clicked on the MyDelegate instance in the MainWindow.xib window, and then I dragged a connection from the outlet 'textField' to the NSTextField(in the app's main window).

 

7) I saved in IB, then build&run (save everything), and this time when I typed in the textfield, the message was not logged to the Debug Console.

 

What is the matter with setDelegate:?  Why doesn't setDelegate: succeed in setting up the delegate so that I can see the message logged to the console?

 

Thanks


View the original article here

Beginning cocoa programming: delegates

Xcode 3.2.2

Mac OS X 10.6.8

Cocoa Programming for Mac OS X (third edition)

Chapter 6: Helper objects

 

What happened to the forum software?  I can't quote text/code anymore.

 

I'm trying to create a simple delegate for an NSWindow.  The delegate implements this method:

 

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;

 

I can get my delegate to work if I use Interface Builder to connect my app's main(and only) window to an instance of my object(which appears in the MainMenu.xib inspector in IB).  However, I cannot get a delegate to work if I call setDelegate: on my app's main window.  In the book, there is one example where they use setDelegate: to setup the delegate object.  There is another example where they use IB to hook up the delegate.  The only distinction I can detect between the two examples is that in the one that employs setDelegate:, the delegate-or is not a widget, and in the one that uses IB to make the connection, the delegate-or is a widget.

 

This is the code that I used to try and programmatically set up a delegate:

 

//AppController.h

 

#import

 

@interface AppController : NSObject {

 

  IBOutlet NSWindow* window;

}

- (id)init;

 

 

@end

 

 

 

//AppController.m

 

#import "AppController.h"

#import "MyDelegate.h"

 

@implementation AppController

 

- (id)init

{

 

  if (![super init]) {

  return nil;

  }

 

  MyDelegate* aDelegate = [[MyDelegate alloc] init];

  [window setDelegate:aDelegate];

 

  return self;

}

 

 

@end


 

 

 

//MyDelegate.h

 

#import

 

@interface MyDelegate : NSObject {

 

}

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;

 

 

@end

 

 

 

//MyDelegate.m

 

#import "MyDelegate.h"

 

 

@implementation MyDelegate

 

 

- (NSSize)windowWillResize:(NSWindow *)sender

                         toSize:(NSSize)frameSize

{

     frameSize.height = 2 * frameSize.width;

     return frameSize;

}

 

 

@end


 

 

In IB, I went into the Library, and I dragged an Object to the MainMenu.xib window/inspector, and I named it AppController.  Then I dragged a connection from the AppController outlet named 'window' to the NSWindow.  When I build&run my code, I can resize the window to any size--the window size is not constrained to a 2:1 ratio. That is not the result I expect: I expect the window size to maintain a 2:1 ration. If I set an object's delegate, then when the event occurs, the object should grab the delegate and use it to call the delegation methods; there is nothing more I should have to do in my code.  What am I not understanding about cocoa delegates?


View the original article here

Re: Beginning cocoa programming: delegates

I constructed another simple example of a delegate: I created an app with one lone NSTextField on the window.  I wanted to see if setDelegate: would work with a different widget(NSTextField v. NSWindow).  My goal was to see if I could setup a delegate using setDelegate: on an NSTextField, such that a delegate method would be called when I typed in the text field.  I  looked through the documentation, and I decided to to see if implementing this delegate method would work:

 

- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor;

 

 

I created a new app(deleting the classes that Xcode automatically creates, as well as the instance in the MainWindow.xib window in IB), and then I created this class:

 

 

//MyDelegate.h

 

import

 

@interface MyDelegate : NSObject {

}

- (BOOL)control:(NSControl *)control

          textShouldBeginEditing:(NSText *)fieldEditor;

 

@end

 

 

//MyDelegate.m

 

@implementation MyDelegate

 

- (BOOL)control:(NSControl *)control

               textShouldBeginEditing:(NSText *)fieldEditor

{

          NSLog(@"***In delegate method...");

          return YES;

}

 

@end

 

 

1) In IB, I created an instance of MyDelegate by dragging an Object from the Library onto the MainWindow.xib window.  I entered the name MyDelegate in the TextField Identity Inspector.

 

2) In IB, I ctrl-clicked on the NSTextField, and then I dragged a connection from NSTextField's 'delegate' outlet to the MyDelegate instance(in the MainWindow.xib window).

 

3) Saved everything, build&run, and when I typed in the text field, I saw the logged message in the Debugger Console, as expected.

 

Next, I attempted to create code that uses setDelegate: to achieve the same thing as above.

 

4) In IB, I ctrl-clicked on the NSTextField and deleted the connection from the 'delegate' outlet to the MyDelegate instance.

 

5)  I made these changes to the code:

 

//MyDelegate.h

 

#import

 

@interface MyDelegate : NSObject {

 

          IBOutlet NSTextField* textField;

}

- (id)init;

- (BOOL)control:(NSControl *)control

          textShouldBeginEditing:(NSText *)fieldEditor;

 

@end

 

 

//MyDelegate.m

#import "MyDelegate.h"

 

@implementation MyDelegate

 

- (id) init

{

          if (![super init]) {

                    return nil;

          }

 

          [textField setDelegate:self];

 

          return self;

}

 

- (BOOL)control:(NSControl *)control

          textShouldBeginEditing:(NSText *)fieldEditor

{

          NSLog(@"***In delegate method...");

          return YES;

}

 

@end

 

 

6) In IB, I ctrl-clicked on the MyDelegate instance in the MainWindow.xib window, and then I dragged a connection from the outlet 'textField' to the NSTextField(in the app's main window).

 

7) I saved in IB, then build&run (save everything), and this time when I typed in the textfield, the message was not logged to the Debug Console.

 

What is the matter with setDelegate:?  Why doesn't setDelegate: succeed in setting up the delegate so that I can see the message logged to the console?

 

Thanks


View the original article here

Thursday, February 21, 2013

Printing iwork documents like ipages,keynote,numbers file using cocoa console application

Please help in order to resolve the printing issue that i am facing while coding in objective c.

I want to print any file like (*.pages,*.numbers,*.keynote)

but i am not able to print these files using PMPrinterPrintWithFile function of objective c

I am able to print other files like *.txt,*.jpeg,*.png, *.pdf.

 

 

when I try to print iwork document like *.pages file with PMPrinterPRintWithFile, it returns a status as 1028

when I am printing other files like *.pdf,*.txt it is printed easily with status 0

 

 

and one more point I am not able to find out the MimeType of files like *.pages,*.number,*.keynote

the MIMETYPE object gets NULL value when i fetch it using the below code.

The Code I am using :

 

 

    #import "Cocoa/Cocoa.h"

 

 

    int main(int argc, char *argv[])

    {

 

 

    NSPrintInfo *printInfo = [[NSPrintInfo alloc] init];

    PMPrintSession myPrintSession= (PMPrintSession)[printInfo PMPrintSession];

    PMPrintSettings printSetting= (PMPrintSettings)[printInfo PMPrintSettings];

    PMPageFormat pageFormat=(PMPageFormat)[printInfo PMPageFormat];

    OSStatus err = PMCreateSession(&myPrintSession);

    OSStatus status;

    CFURLRef fileURL =(CFURLRef) [NSURL fileURLWithPath:@"filename example *.*"];

    NSString* filePath=@"filename ex *.*";

    NSString* FullPath=[filePath stringByExpandingTildeInPath];

    NSURL * url= [NSURL fileURLWithPath:FullPath];

    NSURLRequest* fileUrlRequest = [[NSURLRequest alloc] initWithURL:url];

    NSError* error = nil;

    NSURLResponse* response = nil;

    NSData* fileData = [NSURLConnection sendSynchronousRequest:fileUrlRequest

    returningResponse:&response error:&error];

    NSString * MIMETYPE= [response MIMEType];

    [fileUrlRequest release];

    NSLog(@"MIMETYPE %@",MIMETYPE);

    PMPrinter thisPrinter= "printername";

    status = PMPrinterGetMimeTypes(thisPrinter, printSetting,&mimeTypes);

    if(status==noErr)

          {

          status= PMPrinterPrintWithFile(thisPrinter, printSetting, pageFormat,     

        (CFStringRef)MIMETYPE, fileURL);

          NSLog(@" value :%@",MIMETYPE);

          NSLog(@"%i",status);

          NSLog(@"=======Printer %@=======", PMPrinterGetName( thisPrinter) );

          }

          [printInfo release];

      return 0;

    return NSApplicationMain(argc,  (const char **) argv);

    }


View the original article here

Printing iwork documents like ipages,keynote,numbers file using cocoa console application

Please help in order to resolve the printing issue that i am facing while coding in objective c.

I want to print any file like (*.pages,*.numbers,*.keynote)

but i am not able to print these files using PMPrinterPrintWithFile function of objective c

I am able to print other files like *.txt,*.jpeg,*.png, *.pdf.

 

 

when I try to print iwork document like *.pages file with PMPrinterPRintWithFile, it returns a status as 1028

when I am printing other files like *.pdf,*.txt it is printed easily with status 0

 

 

and one more point I am not able to find out the MimeType of files like *.pages,*.number,*.keynote

the MIMETYPE object gets NULL value when i fetch it using the below code.

The Code I am using :

 

 

    #import "Cocoa/Cocoa.h"

 

 

    int main(int argc, char *argv[])

    {

 

 

    NSPrintInfo *printInfo = [[NSPrintInfo alloc] init];

    PMPrintSession myPrintSession= (PMPrintSession)[printInfo PMPrintSession];

    PMPrintSettings printSetting= (PMPrintSettings)[printInfo PMPrintSettings];

    PMPageFormat pageFormat=(PMPageFormat)[printInfo PMPageFormat];

    OSStatus err = PMCreateSession(&myPrintSession);

    OSStatus status;

    CFURLRef fileURL =(CFURLRef) [NSURL fileURLWithPath:@"filename example *.*"];

    NSString* filePath=@"filename ex *.*";

    NSString* FullPath=[filePath stringByExpandingTildeInPath];

    NSURL * url= [NSURL fileURLWithPath:FullPath];

    NSURLRequest* fileUrlRequest = [[NSURLRequest alloc] initWithURL:url];

    NSError* error = nil;

    NSURLResponse* response = nil;

    NSData* fileData = [NSURLConnection sendSynchronousRequest:fileUrlRequest

    returningResponse:&response error:&error];

    NSString * MIMETYPE= [response MIMEType];

    [fileUrlRequest release];

    NSLog(@"MIMETYPE %@",MIMETYPE);

    PMPrinter thisPrinter= "printername";

    status = PMPrinterGetMimeTypes(thisPrinter, printSetting,&mimeTypes);

    if(status==noErr)

          {

          status= PMPrinterPrintWithFile(thisPrinter, printSetting, pageFormat,     

        (CFStringRef)MIMETYPE, fileURL);

          NSLog(@" value :%@",MIMETYPE);

          NSLog(@"%i",status);

          NSLog(@"=======Printer %@=======", PMPrinterGetName( thisPrinter) );

          }

          [printInfo release];

      return 0;

    return NSApplicationMain(argc,  (const char **) argv);

    }


View the original article here

Tuesday, January 15, 2013

Problem moving xcode cocoa c++ app to other mac's

Hi everyone,

 

My apologies if I am posting this in the wrong forum/section.

 

I am developing a C++ Cocoa app using the latest version of XCode on my MACOS which is running Mountain Lion. It is a fairly simple C++ app but upon copying the executable to another machine, it states that it will not run due to the version of MACOS being different. Apparently my wife has 10.7.5 and I have version > 10.8 so I'm confused how I can make my simple C++ app written in Cocoa work on other macs. Any advice would be greatly appreciated.

 

Thank you


View the original article here

Friday, January 11, 2013

Problem moving xcode cocoa c++ app to other mac's

Hi everyone,

 

My apologies if I am posting this in the wrong forum/section.

 

I am developing a C++ Cocoa app using the latest version of XCode on my MACOS which is running Mountain Lion. It is a fairly simple C++ app but upon copying the executable to another machine, it states that it will not run due to the version of MACOS being different. Apparently my wife has 10.7.5 and I have version > 10.8 so I'm confused how I can make my simple C++ app written in Cocoa work on other macs. Any advice would be greatly appreciated.

 

Thank you


View the original article here

Problem moving xcode cocoa c++ app to other mac's

Hi everyone,

 

My apologies if I am posting this in the wrong forum/section.

 

I am developing a C++ Cocoa app using the latest version of XCode on my MACOS which is running Mountain Lion. It is a fairly simple C++ app but upon copying the executable to another machine, it states that it will not run due to the version of MACOS being different. Apparently my wife has 10.7.5 and I have version > 10.8 so I'm confused how I can make my simple C++ app written in Cocoa work on other macs. Any advice would be greatly appreciated.

 

Thank you


View the original article here

Re: Problem moving xcode cocoa c++ app to other mac's

Set your Deployment OS to 10.7.


View the original article here