完善一个CoreData + NSXMLParser demo

| No Comments | No TrackBacks
XMLdemo.zip

代码就不贴了

UIViewAnimation with block

| No Comments | No TrackBacks

UIViewAnimationWithBlocks使用block,动画结束后不需要使用回调方法,相比UIViewAnimation 方式要简洁很多


- (void)setSelectedVeg:(id)sender

{    

    [selectedVegetableIcon setAlpha:0.0];

    

    [UIView animateWithDuration:0.4

                     animations: ^{

                         float angle = [self spinnerAngleForVegetable:sender];

                         [vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];

                     } 

                     completion:^(BOOL finished) {

                         [selectedVegetableIcon setAlpha:1.0];

                     }];


}

以上代码来自WWDC2010 iPlant PlantCareViem.m


UIViewAnimation style Animation

- (void)setSelectedVeg:(id)sender

{    

    [selectedVegetableIcon setAlpha:0.0];

[UIView beginAnimations:@"setSelectedVeg" context:nil];

float angle = [self spinnerAngleForVegetable:sender];

[vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];

[UIView setAnimationDuration:0.4];

[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector(done)];

[UIView commitAnimations];

}

-(void)done

{

[selectedVegetableIcon setAlpha:1.0];

}

lldb help

| No Comments | No TrackBacks
MacBook-Pro:~ yarshure$ /Users/yarshure/lldb/lldb/build/Debug/lldb 
(lldb) help
The following is a list of built-in, permanent debugger commands:

alias        -- Allows users to define their own debugger command abbreviations.
append       -- Allows the user to append a value to a single debugger setting variable, for settings that are of list types. Type 'settings' to see a list of debugger setting variables
apropos      -- Finds a list of debugger commands related to a particular word/subject.
breakpoint   -- A set of commands for operating on breakpoints.
call         -- Call a function.
delete       -- Lists the kinds of objects you can delete, and shows syntax for deleting them.
disassemble  -- Disassemble bytes in the current function or anywhere in the inferior program.
expression   -- Evaluate a C expression in the current program context, using variables currently in scope.
file         -- Sets the file to be used as the main executable by the debugger.
frame        -- A set of commands for operating on the current thread's frames.
help         -- Shows a list of all debugger commands, or give details about specific commands.
image        -- Access information for one or more executable images.
info         -- Lists the kinds of objects for which you can get information, and shows the syntax for doing so.
log          -- A set of commands for operating on logs.
memory       -- A set of commands for operating on a memory.
process      -- A set of commands for operating on a process.
quit         -- Quits out of the LLDB debugger.
regexp-break -- Smart breakpoint command (using regular expressions).
register     -- Access thread registers.
script       -- Passes an expression to the script interpreter for evaluation and returns the results. Drops user into the interactive interpreter if no expressions are given.
select       -- Lists the kinds of objects you can select, and shows syntax for selecting them.
set          -- Allows the user to set or change the value of a single debugger setting variable.
settings     -- Lists the debugger settings variables available to the user to 'set' or 'show'.
show         -- Allows the user to see a single debugger setting variable and its value, or lists them all.
source       -- Reads in debugger commands from the file <filename> and executes them.
source-file  -- Display source files from the current executable's debug info.
target       -- A set of commands for operating on debugger targets.
thread       -- A set of commands for operating on one or more thread within a running process.
unalias      -- Allows the user to remove/delete a user-defined command abbreviation.
variable     -- Access program arguments, locals, static and global variables.

The following is a list of your current command abbreviations (see 'alias' for more info):

bt       -- ('thread backtrace')  Shows the stack for one or more threads.
c        -- ('process continue')  Continues execution all threads in the current process.
continue -- ('process continue')  Continues execution all threads in the current process.
exit     -- ('quit')  Quits out of the LLDB debugger.
expr     -- ('expression')  Evaluate a C expression in the current program context, using variables currently in scope.
finish   -- ('thread step-out')  Source level single step out in specified thread (current thread, if none specified).
l        -- ('source-file')  Display source files from the current executable's debug info.
list     -- ('source-file')  Display source files from the current executable's debug info.
n        -- ('thread step-over')  Source level single step over in specified thread (current thread, if none specified).
next     -- ('thread step-over')  Source level single step over in specified thread (current thread, if none specified).
q        -- ('quit')  Quits out of the LLDB debugger.
r        -- ('process launch')  Launches the executable in the debugger.
run      -- ('process launch')  Launches the executable in the debugger.
s        -- ('thread step-in')  Source level single step in in specified thread (current thread, if none specified).
si       -- ('thread step-inst')  Single step one instruction in specified thread (current thread, if none specified).
step     -- ('thread step-in')  Source level single step in in specified thread (current thread, if none specified).
x        -- ('memory read')  Read memory from the process being debugged.

For more information on any particular command, try 'help <command-name>'.
Enhanced by Zemanta

Invalid update: invalid number of sections

| No Comments | No TrackBacks

2010-06-15 09:35:14.408 JoyPlayer[494:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:772

2010-06-15 09:35:14.408 JoyPlayer[494:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'

2010-06-15 09:35:14.409 JoyPlayer[494:207] Stack: (

    36209755,

    2528503049,

    36293691,

    2776852,

    5075846,

    5020217,

    43132,

    387640,

    2454948,

    2454803,

    32134584,

    32132632,

    32135830,

    31795157,

    35993825,

    35990600,

    41654157,

    41654354,

    4763651,

    10756,

    10610

)

InAppSMS

| No Comments | No TrackBacks

- (IBAction)sendSMS {

BOOL canSendSMS = [MFMessageComposeViewController canSendText];

NSLog(@"can send SMS [%d]", canSendSMS);

if (canSendSMS) {

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];

picker.messageComposeDelegate = self;

picker.navigationBar.tintColor = [UIColor blackColor];

picker.body = @"test";

picker.recipients = [NSArray arrayWithObject:@"186-0123-0123"];

[self presentModalViewController:picker animated:YES];

[picker release];

}

}


- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

// Notifies users about errors associated with the interface

switch (result) {

case MessageComposeResultCancelled:

if (DEBUG) NSLog(@"Result: canceled");

break;

case MessageComposeResultSent:

if (DEBUG) NSLog(@"Result: Sent");

break;

case MessageComposeResultFailed:

if (DEBUG) NSLog(@"Result: Failed");

break;

default:

break;

}

[self dismissModalViewControllerAnimated:YES];

}

KongXiangBo-iPad:~ root# hostinfo

| No Comments | No TrackBacks
KongXiangBo-iPad:~ root# hostinfo
Mach kernel version:
Darwin Kernel Version 10.3.1: Mon Mar 15 23:15:33 PDT 2010; root:xnu-1504.2.27~18/RELEASE_ARM_S5L8930X
Kernel configured for a single processor only.
1 processor is physically available.
1 processor is logically available.
Processor type: armv7 (arm v7)
Processor active: 0
Primary memory available: 247.00 megabytes
Default processor set: 27 tasks, 184 threads, 1 processors
Load average: 0.06, Mach factor: 0.93

UINavigationBar 背景Hack

| No Comments | No TrackBacks

LOGO_320×44.png 图片显示在背景上,

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawRect:(CGRect)rect {

//加入旋转坐标系代码

    // Drawing code

UIImage *navBarImage = [UIImage imageNamed:@"LOGO_320×44.png"];

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextTranslateCTM(context, 0.0, self.frame.size.height);

CGContextScaleCTM(context, 1.0, -1.0);

CGPoint center=self.center;


CGImageRef cgImage= CGImageCreateWithImageInRect(navBarImage.CGImage, CGRectMake(0, 0, 1, 44));

CGContextDrawImage(context, CGRectMake(center.x-160-80, 0, 80, self.frame.size.height), cgImage);

CGContextDrawImage(context, CGRectMake(center.x-160, 0, 320, self.frame.size.height), navBarImage.CGImage);

CGContextDrawImage(context, CGRectMake(center.x+160, 0, 80, self.frame.size.height), cgImage);


}

@end

old code

CGContextDrawImage(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), navBarImage.CGImage);

hack 过logo 不再拉伸
nav_bar.png


sel_registerName 使用

| No Comments | No TrackBacks
Q: 已知一个字符串,如何让objctive c 实例执行字符串代笔的方法?
A: 使用sel_registerName 注册成SEL,然后使用respondsToSelector判断是否可以执行,如果可以执行,那么使用performSelector 来执行

- (void)configureView:(NSString *)performaction {


if ([performaction length] >0) {

SEL sel=sel_registerName([performaction UTF8String]);

if ([self respondsToSelector:sel]) {

[self performSelector:sel];

}

}

}

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




UIWebView &WebKit target == '_blank'

| No Comments | No TrackBacks
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 不会写,只能读读。

iPAD 链接外置显示器

| No Comments | No TrackBacks

iPhone SDK 3.2 /4.0 模拟器支持电视输出,可选分辨率为
640*480
1024*168
1280*720 720p

屏幕快照 2010-05-02 上午01.27.22.png
ipad_extern_displayer.png


RegexKitLite 使用

| No Comments | No TrackBacks

RegexKitLite 之前搞过,但是内弄清楚,这次必须搞好。

下面是测试代码,在SDK 4.0 上通过。3.2一下NSRegularExpressionSearch 不支持,自己想办法吧。


-(void)test

{

NSString *html=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1.html" ofType:nil] encoding:NSUTF8StringEncoding error:nil];

//NSString *exp=@"/(https?)://(\\d+))?((?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\]*)+)?/";

NSString *exp=@"http://[^ ]*.(png|jpeg|PNG|JPEG|JPG|jpg)";

NSRange r;

for(NSString *match in [html componentsMatchedByRegex:exp]) {

NSLog(@"111Phone number is %@", match);

}

r = [html rangeOfString:exp options:NSRegularExpressionSearch];

if (r.location != NSNotFound) {

NSLog(@"Phone number is %@", [html substringWithRange:r]);

} else {

NSLog(@"Not found.");

}

}

Apple Push Notification ADHOC测试

| 1 Comment | No TrackBacks
1 需要PushMebaby 原代码,简单的demo 程序
2 参考其他文档做就可以了
  唯一不有问题的是PushMebaby 没有针对ADHoc 做调整,需要调整的代码
dev 环境

result = MakeServerConnection("gateway.sandbox.push.apple.com", 2195, &socket, &peer);

result = SSLSetPeerDomainName(context, "gateway.push.apple.com", 30);


ADHOC

result = MakeServerConnection("gateway.push.apple.com", 2195, &socket, &peer);

result = SSLSetPeerDomainName(context, "gateway.push.apple.com", 22);


这这个地方要注意DomainName 长度变了,是22不是30。在这个地方上浪费时间了,反复生成cert 文件好几次。

上图

epad_push_notification.png

后面是app delegate class 需要增加的代码

操蛋的代码

| No Comments | No TrackBacks

if( homeViewObj != nil )

{

channelViewObj = [[CChannelsView alloc] init];

if( channelViewObj != nil

{

searchViewObj = [[CSearchView alloc] init];

if( searchViewObj != nil )

{

downloadViewObj = [[CDownloadView alloc] init];

if( downloadViewObj != nil )

{

topicNaviObj = [[CTopicNavi alloc] init];

if ( topicNaviObj != nil )

{

rankingNaviObj = [[CRankingNaviView alloc] init];

if ( rankingNaviObj != nil )

{

collectionNaviObj = [[CollectionNavi alloc] init];

if ( collectionNaviObj != nil )

iPad 256M 内存

| No Comments | No TrackBacks
sysctl.png

iPhone 4.0 来了

| No Comments | No TrackBacks
iPhone4.PNG
1 多任务支持
2 iAD 广告系统
3 GameCenter
4 企业功能增强,运行企业内部发布,不需要iTunes 同步了,这个很好。
多个 Exchange 账户
6 Mail 增强
 
mail.PNG
详细细节看发布会视频或者新闻吧。

另外
iPhone OS 4.0 基于Darwin 10.3,既 SnowLeopard 10.6.3 
baseband 5.13.03 (3GS) 不同于 3.1.3

libsndfile 移植到iPhone 搞定

| 2 Comments | No TrackBacks
可以转化任何90%声音文件格式。
测试了下caf to wav, caf to amr
wav to amr 以前就搞定。

波折很多,最初打算裁剪,疯狂删除不用的.c
结果失败,走人迷途。

从入口点开始添加.c 文件,越添加越多。

后来的想法开始也不work,但是小量修改后成功。

支持iPhone + 模拟器。

iPad 播放视频

| 3 Comments | No TrackBacks
MPMoviePlayerController 不能正常工作了,需要MPMoviePlayerViewController

写了几个测试方法,可以play了,哈哈,另外写了获取缩略图的代码

屏幕快照 2010-03-10 下午05.26.09.png

变态的多种分类设计

| No Comments | No TrackBacks
UITabBarController 进入某个tableViewcontroller后,在进入tableViewcontroller
这个时候如果再点击当前的TabBarItem,会自动调用popViewControllerAnimated
变态设计要出现几个分类按钮,解决问题关键

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

{

// NSLog(@"good to see it");

if (self.selectedViewController == viewController ) {

if ([((UINavigationController*)viewController).visibleViewController  respondsToSelector:@selector(showCategoryBtns)]) {

[ (TableViewController*)(((UINavigationController*)viewController).visibleViewController) showCategoryBtns];

return NO;解决问题关键

}

}

return YES;

}

Find recent content on the main index or look in the archives to find all content.

Recent Comments

  • 孔祥波: baoyifeng read more
  • baoyifeng: 我按照你的代码运行了 read more
  • 利刃: 您好,我现在开发第三 read more
  • 宋彼得: 孔先生,你好 read more
  • Sean: 听说只要是越狱iPh read more
  • Jing: 感谢~ 我也遇到了这 read more
  • 石松: 你好,能不能也发个例 read more
  • 陈心涛: 您好,我是华南理工大 read more
  • 孔祥波: 窘,发现libsnd read more
  • 孔祥波: 改方法吧,增加了一个 read more

Recent Assets

  • nav_bar.png
  • 屏幕快照 2010-05-02 上午01.27.22.png
  • ipad_extern_displayer.png
  • epad_push_notification.png
  • sysctl.png
  • mail.PNG
  • iPhone4.PNG
  • 屏幕快照 2010-03-10 下午05.26.09.png
  • gameing_on_tv.png
  • iphone_tv.png

页面

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.32-en