2010 Archives

NSOperation and KVO/KVC coding

| No Comments | No TrackBacks

本文简要介绍如何使用KVO 跟踪NSOperation 状态


traceOperation 方法跟踪 PageLoadOperation(NSOperation 子类)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    

    // Override point for customization after app launch 

for (NSString *urlString in urlArray

{

        NSURL *url = [NSURL URLWithString:urlString];

        PageLoadOperation *plo = [[PageLoadOperation alloc] initWithURL:url];

        [queue addOperation:plo];

[self traceOperation:plo];

        [plo release];

    }

    [window addSubview:viewController.view];

    [window makeKeyAndVisible];

return YES;

}

traceOperation 方法

KeyPath 官方文档说明 http://developer.apple.com/mac/library/documentation/cocoa/reference/NSOperation_class/Reference/Reference.html#//apple_ref/doc/c_ref/NSOperation

KVO-Compliant Properties

The NSOperation class is key-value coding (KVC) and key-value observing (KVO) compliant for several of its properties. As needed, you can observe these properties to control other parts of your application. The properties you can observe include the following:

  • isCancelled - read-only property

  • isConcurrent - read-only property

  • isExecuting - read-only property

  • isFinished - read-only property

  • isReady - read-only property

  • dependencies - read-only property

  • queuePriority - readable and writable property

  • completionBlock - readable and writable property (Mac OS X only)

-(void)traceOperation:(NSOperation*)obj

{

[obj addObserver:self

  forKeyPath:@"isExecuting"

  options:0

  context:NULL];

[obj addObserver:self

  forKeyPath:@"isFinished"

  options:0

  context:NULL];

[obj addObserver:self

  forKeyPath:@"isReady"

options:0

context:NULL];

[obj addObserver:self

  forKeyPath:@"isCancelled"

options:0

context:NULL];

}


Using C++ With Objective-C

| No Comments | No TrackBacks

//

//  Greeting.h 头文件

//  cpp_demo

//

//  Created by 孔祥波 on 10-5-24.

//  Copyright 2010 aaa. All rights reserved.

//


#import <Foundation/Foundation.h>


class Hello {

private:

id greeting_text// holds an NSString

public:

Hello() {

greeting_text = @"Hello, world!";

}

Hello(const char* initial_greeting_text) {

greeting_text = [[NSString alloc] initWithUTF8String:initial_greeting_text];

}

void say_hello() {

printf("%s\n", [greeting_text UTF8String]);

}

};


@interface Greeting : NSObject {

@private

Hello *hello;

}

- (id)init;

- (void)dealloc;

- (void)sayGreeting;

- (void)sayGreeting:(Hello*)greeting;

@end




http://www.icab.de/blog/category/programming/
有两篇很好的文章关于 target == '_blank' window.open(url, "_blank");
WebKit on the iPhone (Part 2)
http://niw.at/articles/2009/02/06/how-to-enable-the-popup-window-on-uiwebview/en
 这里讲的也不错

偶不是搞Web开发JS 不会写,只能读读。