Ray's playground

 

随笔分类 -  Mac

1 2 下一页

Blocks(Chapter 3 of Advanced Mac OS X Programming)
摘要:#import<Foundation/Foundation.h>intmain(intargc,constchar*argv[]){@autoreleasepool{//insertcodehere...NSLog(@"Hello,World!");NSArray*array=[NSArrayarrayWithObjects:@"Ray",@"Summer",nil];[arrayenumerateObjectsUsingBlock:^(idobj,NSUIntegeridx,BOOL*stop){NSLog(@" 阅读全文

posted @ 2011-12-19 17:40 Ray Z 阅读(279) 评论(0) 推荐(0)

Core Data Relationships(Chapter 30 of Cocoa Programming for Mac OS X)
摘要:1#import"Department.h"2#import"Employee.h"34@implementationDepartment5@dynamicdeptName;6@dynamicemployees;7@dynamicmanager;89/*10-(void)addEmployeesObject:(NSManagedObject*)value{11NSSet*changedObjects=[[NSSetalloc]initWithObjects:&valuecount:1];12[selfwillChangeValueForKey:@ 阅读全文

posted @ 2011-04-06 19:59 Ray Z 阅读(240) 评论(0) 推荐(0)

View Swapping(Chapter 29 of Cocoa Programming for Mac OS X)
摘要:1#import"MyDocument.h"2#import"DepartmentViewController.h"3#import"EmployeeViewController.h"45@implementationMyDocument67-(id)init8{9[superinit];10viewControllers=[[NSMutableArrayalloc]init];1112ManagingViewController*vc=[[DepartmentViewControlleralloc]init];13[vcsetMan 阅读全文

posted @ 2011-04-02 14:32 Ray Z 阅读(304) 评论(0) 推荐(0)

Web Service(Chapter 28 of Cocoa Programming for Mac OS X)
摘要:1#import"AppController.h"2#defineAWS_ID@"1CKE6MZ6S27EFQ458402"34@implementationAppController56-(id)init7{8self=[superinit];9if(self){10//Initializationcodehere.11}1213returnself;14}1516-(IBAction)fetchBooks:(id)sender17{18[progressstartAnimation:nil];1920NSString*input=[searchFie 阅读全文

posted @ 2011-03-22 15:06 Ray Z 阅读(340) 评论(0) 推荐(0)

Printing(Chapter 27 of Cocoa Programming for Mac OS X)
摘要:1#import"PeopleView.h"2#import"Person.h"34@implementationPeopleView56-(id)initWithPeople:(NSArray*)persons7{8[superinitWithFrame:NSMakeRect(0,0,700,700)];9people=[personscopy];10attributes=[[NSMutableDictionaryalloc]init];11NSFont*font=[NSFontfontWithName:@"Monaco"size: 阅读全文

posted @ 2011-03-14 11:43 Ray Z 阅读(280) 评论(0) 推荐(0)

Creating NSFormatters(Chapter 26 of Cocoa Programming for Mac OS X)
摘要:1#import"ColorFormatter.h"23@interfaceColorFormatter()45-(NSString*)firstColorKeyForPartialString:(NSString*)string;67@end89@implementationColorFormatter1011-(id)init12{13[superinit];14colorList=[[NSColorListcolorListNamed:@"Apple"]retain];15returnself;16}1718-(void)dealloc19{20[ 阅读全文

posted @ 2011-03-11 09:19 Ray Z 阅读(233) 评论(0) 推荐(0)

Sheets(Chapter 25 of Cocoa Programming for Mac OS X)
摘要:1//2//AppController.m3//TypingTutor4//5//Createdbyb1mobileon3/3/11.6//Copyright2011__MyCompanyName__.Allrightsreserved.7//89#import"AppController.h"10#import"BigLetterView.h"1112#defineMAX_COUNT(100)13//#defineCOUNT_STEP(5)1415@implementationAppController1617-(id)init18{19[superi 阅读全文

posted @ 2011-03-08 17:36 Ray Z 阅读(200) 评论(0) 推荐(0)

NSTimer(Chapter 24 of Cocoa Programming for Mac OS X)
摘要:1#import"AppController.h"2#import"BigLetterView.h"34#defineMAX_COUNT(100)5#defineCOUNT_STEP(5)67@implementationAppController89-(id)init10{11[superinit];1213letters=[[NSArrayalloc]initWithObjects:@"a",@"s",@"d",@"f",@"j",@"k&q 阅读全文

posted @ 2011-03-05 13:20 Ray Z 阅读(281) 评论(0) 推荐(0)

Drag-and-Drop(Chapter 23 of Cocoa Programming for Mac OS X)
摘要:#import"BigLetterView.h"@implementationBigLetterView-(NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal{returnNSDragOperationCopy|NSDragOperationDelete;}-(NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender{NSDragOperationop=[senderdraggingSourceOperationMask]; 阅读全文

posted @ 2011-03-03 10:43 Ray Z 阅读(516) 评论(0) 推荐(1)

Pasteboards and Nil-Targeted Actions(Chapter 21 of Cocoa Programming for Mac OS X)
摘要:1-(void)writeToPasteboard:(NSPasteboard*)pb2{3[pbdeclareTypes:[NSArrayarrayWithObject:NSStringPboardType]owner:self];4[pbsetString:stringforType:NSStringPboardType];5}67-(BOOL)readFromPasteboard:(NSPasteboard*)pb8{9NSArray*types=[pbtypes];10if([typescontainsObject:NSStringPboardType])11{12NSString*v 阅读全文

posted @ 2011-03-02 09:41 Ray Z 阅读(239) 评论(0) 推荐(1)

Drawing Text With Attributes(Chapter 20 of Cocoa Programming for Mac OS X)
摘要:1#import"BigLetterView.h"234@implementationBigLetterView56-(IBAction)savePDF:(id)sender7{8NSSavePanel*panel=[NSSavePanelsavePanel];9[panelsetRequiredFileType:@"pdf"];10[panelbeginSheetForDirectory:nilfile:nilmodalForWindow:[selfwindow]modalDelegate:selfdidEndSelector:@selector(di 阅读全文

posted @ 2011-03-01 14:52 Ray Z 阅读(694) 评论(0) 推荐(0)

Keyboard Events(Chapter 19 of Cocoa Programming for Mac OS X)
摘要:1#import"BigLetterView.h"234@implementationBigLetterView56-(id)initWithFrame:(NSRect)frameRect7{8if(![superinitWithFrame:frameRect])9{10returnnil;11}1213NSLog(@"initializingview");14bgColor=[[NSColoryellowColor]retain];15string=@"";16returnself;17}1819-(void)dealloc20{2 阅读全文

posted @ 2011-02-28 17:03 Ray Z 阅读(410) 评论(0) 推荐(0)

Images and Mouse Events(Chapter 18 of Cocoa Programming for Mac OS X)
摘要:1#import"StretchView.h"234@implementationStretchView56-(id)initWithFrame:(NSRect)rect7{8if(![superinitWithFrame:rect])9{10returnnil;11}1213srandom(time(NULL));1415path=[[NSBezierPathalloc]init];16[pathsetLineWidth:3.0];17NSPointp=[selfrandomPoint];18[pathmoveToPoint:p];19inti;20for(i=0;i&l 阅读全文

posted @ 2011-02-24 16:53 Ray Z 阅读(261) 评论(0) 推荐(0)

Custom Views(Chapter 17 of Cocoa Programming for Mac OS X)
摘要:#import"StretchView.h"@implementationStretchView-(id)initWithFrame:(NSRect)rect{if(![superinitWithFrame:rect]){returnnil;}srandom(time(NULL));path=[[NSBezierPathalloc]init];[pathsetLineWidth:3.0];NSPointp=[selfrandomPoint];[pathmoveToPoint:p];inti;for(i=0;i<15;i++){p=[selfrandomPoint];[ 阅读全文

posted @ 2011-02-24 11:17 Ray Z 阅读(211) 评论(0) 推荐(0)

Localization(Chapter 16 of Cocoa Programming for Mac OS X)
摘要:Clearly, as you develop and localize many applications, you will develop a set of common translations. It would be handy to have an automated way to get the translated strings into a nib file. This is one of several uses for ibtool. The ibtoolcommand, which is run from the terminal, can list the cl. 阅读全文

posted @ 2011-02-23 17:41 Ray Z 阅读(167) 评论(0) 推荐(0)

Using Alert Panels(Chapter 15 of Cocoa Programming for Mac OS X)
摘要:The NSRunAlertPanel() function returns an intthat indicates which button the user clicked. There are global variables for these constants: NSAlertDefaultReturn, NSAlertAlternateReturn, and NSAlertOtherReturn. int NSRunAlertPanel(NSString *title, NSString *msg, NSString *defaultButton, NSString *alt. 阅读全文

posted @ 2011-02-23 11:44 Ray Z 阅读(230) 评论(0) 推荐(0)

Using Notifications(Chapter 14 of Cocoa Programming for Mac OS X)
摘要:PreferenceControllerCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#import"PreferenceController.h"234@implementationPreferenceController56NSString*constBNRTableBgColorKey=@"TableBackgroundColor";7NSString*constBNREmptyDocKey= 阅读全文

posted @ 2011-02-23 11:15 Ray Z 阅读(296) 评论(0) 推荐(0)

User Defaults(Chapter 13 of Cocoa Programming for Mac OS X)
摘要:Every application comes with a set of defaults from the factory. When a user edits his or her defaults, only the differences between the user's wishes and the factory defaults are stored in the user's defaults database. Thus, every time the application starts up, you need to remind it of the 阅读全文

posted @ 2011-02-22 13:27 Ray Z 阅读(168) 评论(0) 推荐(0)

Nib Files and NSWindowController(Chapter 12 of Cocoa Programming for Mac OS X)
摘要:PreferenceControllerCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#import"PreferenceController.h"234@implementationPreferenceController56-(id)init7{8if(![superinitWithWindowNibName:@"Preferences"])9{10returnnil;11}1213returnself;14}1516-(void)w 阅读全文

posted @ 2011-02-21 17:25 Ray Z 阅读(270) 评论(0) 推荐(0)

Basic Core Data(Chapter 11 of Cocoa Programming for Mac OS X)
摘要:Apple decided to make this type of application extremely easy to write: NSArrayControllerwill hold on to an array of objects. Bindings will eliminate much of the glue code that would be necessary to keep the model objects in sync with the views. NSManagedObjectContextwill observe the instance v 阅读全文

posted @ 2011-02-16 16:25 Ray Z 阅读(181) 评论(0) 推荐(0)

1 2 下一页

导航