Category Archives: iOS - Page 2

Tutorial of kissXML(iPhone)

KissXML is a good approach for parsing xml data, and the x-path function make it more powerful.

Integrate With You Project And KissXML

  • Download source codes form here
  • Add all the files to your project (excluding DDXMLTesting)
  • Configure you project to work with libxml

click Project -> Edit Project Settings

You’ll be adding this to your compiler instructions

OTHER_LDFLAGS = -lxml2

HEADER_SEARCH_PATHS = /usr/include/libxml2

Using KissXML

Here is a quick demo to indicate you how it works.

For example, we need to get the SRC value of each media field from the target xml file.

<smil xmlns="http://www.w3.org/2000/SMIL20/CR/Language">
<head>
</head>
<body>
<par dur="120000ms" >
<text region="Text" src="att000.txt" />
</par>
<par dur="120000ms" >
<text region="Text" src="att010.txt" />
</par>
<par dur="10000ms" >
<img region="Image" src="att020.jpg"/>
</par>
<par dur="120000ms" >
<text region="Text" src="att040.txt" />
</par>
<par dur="10000ms" >
<img region="Image" src="att120.gif"/>
</par>
</body>
</smil>

Here are the codes !

//hack to remove xmlns => avoid xpath search not works
 xmlStr = [xmlStr stringByReplacingOccurrencesOfString:@"xmlns" withString:@"noNSxml"];
 NSMutableArray* contents = [NSMutableArray array];
 NSError* error = nil;
 DDXMLDocument* xmlDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:&error];
 if (error) {
 NSLog(@"%@",[error localizedDescription]);
 return nil;
 }
 NSArray* resultNodes = nil;
 resultNodes = [xmlDoc nodesForXPath:@"//audio | //text | //image | //img" error:&error];
 if (error) {
 NSLog(@"%@",[error localizedDescription]);
 return nil;
 }
 for(DDXMLElement* resultElement in resultNodes)
 {
 NSString* name = [resultElement name];
 //audio , text or other media type
 NSString* fileName = [[resultElement attributeForName:@"src"] stringValue];
 // 0.txt
 }

Note, I replaced the “xmlns” inside the xml file, because it weird xpath would failed if namespace available at a XML file(it might a bug)

And at last, have fun!

What is iPad All About?

What is iPad All About?

With iPad devices, you now have an opportunity to create Multi-Touch applications on a larger display than previously available. The 1024 x 768 pixel screen provides much more room to display content, or provide greater detail for your existing content. And the addition of new interface elements in iPhone OS 3.2 enable an entirely new breed of applications.

The size and capabilities of iPad mean that it is now possible to create desktop-class applications for a portable device. The increased screen size gives you the space you need to present almost any kind of content. The Multi-Touch interface and support for physical keyboards enables diverse modes of interaction, ranging from simple gesture-drive interaction to content creation and substantial text input.

The increased screen size also makes it possible to create a new class of immersive applications that replicate real-world objects in a digital form. For example, the Contacts and Calendar applications on iPad look more like the paper-based address book and calendar you might have on your desk at home. These digital metaphors for real-life objects provide a more natural and familiar experience for the user and can make your applications more compelling to use. But because they are digital, you can go beyond the limitations of the physical objects themselves and create applications that enable greater productivity and convenience.

对于iPad,还是觉得得写点什么.
这是开发文档中对iPad的定义,同志们,要领会党的精神呀!
太晚了.明天继续.

永远的扫雷英雄(开源) 登场

开源小游戏 永远的扫雷英雄 登场!

写这个游戏的目的就是想写个小教程,后来想想文字就算了,有问题直接留言或邮件更直接. :)

源码:http://github.com/xhan/minesweeperever

游戏介绍

MINE SWEEPER EVER是经典的扫雷iphone版本.你可以在app store上免费下载 Link

mainShot-MineSweeperEver

你可能可以学到什么

  • 一个完整的游戏(片头,菜单,光卡,排行榜)
  • 基本UIKIT界面的使用,手写和nib的混合
  • 不同界面间传递消息
  • 播放视频
  • 简单游戏的状态机
  • UserDefault的使用和简单的排行榜

在编译之前

由于资源文件比较多,开场视频是大头,还有许多策划时涂鸦使用的ps文件,请移步下载 http://ixhan.com/kill/MineSweeperEver-Resource.zip 到当前目录并解压.

为什么写这个小游戏

半年前(May 2009)做毕业设计(PlutoCMS)的时候头昏脑涨,逐下载了iPhoneSDK把玩下,原意是测试下学校带宽并看看iPhone模拟器是什么样子的.结果控制不住看了 iPhone cookbook ,记得第一章有个教你嵌套绘制图层 和 响应手指点击的 两个片段 .于是就想到了由两个技术做个扫雷绰绰有余,两个晚上后做了个只能扫雷不能放置旗帜的半成品就撒手不管.继续回头研究俺的毕业设计了.

离职后的这段时间刚好有些空闲,决定把之前未完成的东西收尾,并开源给有需要的人.花费了一个下午修改完善了下之前的代码,又花了一个晚上和一个早上把其他东西(几个界面,排行榜)添加了上去.最后是UI方面,第一个晚上画了个logo,简单策划了下大概需要的素材,还找了美工朋友帮我画了个坑,可是第二天在ps中做素材发现还是无法掌控美术上的东西,干脆决定用windows上经典的界面.

等待9天后通过审核,然后在那天上海iphone会议上才在mars的真机上见到自己的程序(惭愧呀,iphone因经济危机被我卖了),感觉还不是特别糟糕.哈哈.

许多特性没来得及加上去:

  • 互联网排行榜功能
  • 退出保存当前状态功能
  • 左右手不同界面
  • 长按或双击添加/取消 旗帜功能
  • 荣誉系统 ,包括炸死次数,成功次数,等等.

不过作为一个简单的教程应该还是够了.可能再过几个月闲的没事会改改~.

源码:http://github.com/xhan/minesweeperever

栽大了之Objc过度释放对象

事情是这样的,4个月前我写了份实现类似下拉框选择操作的界面.
一个月前,发现了这个View 在dealloc 会crash掉.
多次调试无果,上 devForum.apple.com 询问也无人问津.
今天决定再次调试下,还是没找到哪里出问题.
最后决定求助 cocoachina 上的现场观众
最后开始一行一行的注释代码做终极调试.

离谱的事情发现了,只要我创建一个名为 mainText 的 UILabel ,在dealloc 中程序就会crash ,改成其他名字无事.难道是apple的bug? 新写了个view测试了,还是没问题.

接着接着就发现了在dealloc方法中:
[mainText release] ,mainText = nil;
// NSLog(@"release %@",bgView);
[bgView release];
// NSLog(@"release %@",originView);
[originView release];
// NSLog(@"release %@",labelArray);
[labelArray release];
// NSLog(@"release %@",mainText);
[mainText release];

该死的,不知道当时那根神经错了,居然释放了两次,当然出错咯.问题也解决了.

所以在确认释放对象的情况下一定要写成:
[instance release],instance = nil ;

个人经验是,对于objective-c的内存管理都是得经过磨练才出来的,前期多犯错误是好事情.
当然我认识一个朋友 ,他不释放任何对象,因为反正关闭iPhone后系统会处理的.这种觉悟不是大部分程序员有的,大家还是稳步前进咯.

Things I’ve done int past 5 months

It’s awfully to say that Time is running out fast , but it really does.

I’ve been working as a iPhone application developer for five months  ,devoting all my energy to my job . Thanks to company’s trust , now I am the core architect and team leader of our small group .

We’ve redesigned most of default iPhone UI components which is  really a difficult job at first . After a several  days of hardworking  ,We released first custom components named ‘MeeTabBarController’ , which is more powerful , flexible, and has ability to manage animations for each tabBar ,each container view’s opening animations and  closing animations. It really works great and appears amazing.

Since now We’ve achieved the custom NavigationController, which has more delegate methods , a incredible user interface  and animations. the custom alertView , the custom tableViewController , the custom spring board , the custom http-client for fetching remote data , etc .

It would be no exaggeration to say that our custom framework is just another lite version of Three20 .^^

Here is a Preview version of Our Project:

NameLinesFiles
Third part header236034
Third part Source491638
Project Header7222170
Project Source28330173
Total42828415
Total Pngs431

Here is a snap shoot of our another application which had submitted to apple store and ready for sale .
It just a simple application that in order to test whether our designs and functions will be rejected or permitted by apple ,Thankfully ,after a mistake that was rejected by undocument api  ,It’s status came out to be  ready for sale finally.



You can search it by type its name “Grading” ,it’s also based on our custom framework and I cost 3 days to finish it.
Give a try and feel free to comment it !(Note : we put off the sale date of this application for the moment by some conditions)

将编译好的iPhone程序的PNG还原

iPhone程序包中的png文件是经过处理,不能直接查看。

如果一定要看!!!好了,这个工具能满足你的好奇心。

Name: iPhonePNG
Usage:  ./iPhonePNG <input>   input 可以是单个png文件也可以是文件夹
download:  iPhonePNGdecoding

以下链接能了解更多这个格式的细节:

Wiki for this png format
The author’s post for this tools

iPhone 组件模板(设计用)分享

还在设计iPhone程式时在草稿纸上涂鸦吗?你out了,使用这款iPhone组件模板并配合OmniGraffle这款软件,只需简单几步就可以设计出原生的iPhone程式界面了。

预览图

预览图

Read more »