看到很刚开始开发iPhone软件的朋友问很多问题,其实同样的问题我也碰到过, 所以抽时间把能想到的或者碰到的问题汇总一下, 一来可以给自己做个备忘也可以和朋友们分享探讨。

ZipArchive is a wrapper class to compress and uncompress zip files for Objective-C and cocoa use. It’s developed based on minizip and zlib.

Recently, I got a task to develop an application for iPhone. In the application, there are some optional choices for user to decide further processes. The first idea jumps out from my head is something like button with a checkbox just the same as other desktop platforms, but unfortunately, iPhone SDK doesn’t provide such view. The only official choice is the ON|OFF switch view, but it really can’t represent the actually meaning of the options. So comes out the idea of writing custom checkbox style button.

Objective-C中的属性
在C++中,类可以有自己的成员变量, 一般公有成员变量可以直接通过类对象访问或修改, 保护成员变量和私有成员变量通过相应的函数来存取,比如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class CPerson
{
public:
	int	 gender;
protected:
	int age;
public:
	int GetAge(){return age;}
	void SetAge( int newValue){ age = newAge;}
};
 
void test(){
	CPerson person;
	person.gender = 0;
	person.SetAge(20);
	printf("性别:%d",person.GetAge() );
	printf("年龄:%d",person.gender);
 
}

Objective-C的内存管理
在Mac OSX 系列操作系统以及iPhone平台上写应用程序时,打开垃圾回收选项,如果程序并不涉及复杂的内存分配, 就几乎可以不用操心内存管理的问题。系统会自动释放部分不用的内存,就像Java那样。

但是如果所编写的程序中有大量内存分配以及频繁释放使用, 这时就需要自己来管理内存。 也就是说,如果你使用alloc方法为对象分配空间, 就应该在使用完后手动发送release消息以释放内存空间

到现在为止,已经学习了如何调用类方法以及创建对象。 到目前为止我们还没有看到如何才能定义一个类, 上两次的内容已经多次涉及到类及类的成员,现在我们可以学习一下如何才能定义一个自己的类。

设计一个类(接口)

一般来讲创建一个类需要两部分,首先是申明类的头文件ClassName.h, 还有类实现的源文件ClassName.m, 如果你想在程序中混合C/C++编程那么就需要使用.mm或者.M ,这样编译器会以此判断该类中混合了Objective-C 和 C语言

Email Marketing with Cyber Port.