object_c 类声明:
@interface 类名:NSObject
{
}
@end
object_c类定义:
@implementation 类名
@end
如下例:
#import <Foundation/Foundation.h>
@interface ABC:NSObject
{
int x;
int y;//instance varaiables
}
@property int x //声明
-(void ) duixiangfangfa: setx:(int ) n//对象方法
+void leifangfa:sety:int (n);//类方法
-void insertObject:(id) anObject atindex:(int)index;//对象方法多个参数调用时【对象名 insertObject:object atindex:index】
实例对象要在要在括号里面;实例方法要在外边;
@end
#import "ABC.h"
@implementation ABC
@synthesize x;//属性实现
@end
@
main.m
@property 通过属性来访问内部变量,而不能直接访问类成员呢;
[对象名 setX:1]
建构造
另外继承不只是NSObject 还有NSException;
时间紧急,还是先学会一些能迅速用到的事情,其他事情以后再说
NSNumber *YY=[NSNumber numberWithFloat:10.0];
[YY floatValue];
%lg %s %f %i
numberWithChar
stringWithString:(NSString *)string
stringWithFormat
NSString *ne=[NSString stringWithFormat:@"%@ Object",NSString *duixiang];
stringByAppendingString
NSString *ne;
NSString *na=[ne StringByAppendingString:@"dsd"];
isEqualToString 相等为1;
[string1 isEqualToString:string2]==1;
hasPrefix:判断开头字母;
uppercaseString lowercaseString
NSLog
substringToIndex substringToindex
substringFromIndex
stringWithContentsOfURL
stringWithContentsOfURL
length NSint
characterAtIndex
UTF8String doubleValue floatValue
NSString * 其实就和const char *一样不可以修改;stringByAppendingString 也是将更改的值赋予新的对象来着;
NSMutableString *string;//构造方法吧:NSMutableString stringWithString:string 构造方法都是NSString 下面的
[string appendString]
appendFormat @“%@”;
insertString:atIndex :5
NSMakeRange
replaceCharactersInRange
数组;
不可修改的数组:arrayWithObjects
NSArray *city=[NSArray arrayWithObjects:@"beijing",@"sh",@"ty",nil]
[city count];
objectAtIndex
[city objectAtIndex:3]
indexOfObject
[city indexOfObject:@"beijing"];
常用方法:
arrayWithObjects :obj1 obj2 nil
(BOOL)containsObject:obj;
count
objectAtIndex//nil
makeObjectsPerformSelector:(SEL) selector;
sortedArrayUsingSelector:(SEL) selector;
NSMutableArray *数组对象名=[[NSMutable alloc]init]
addObject
removeObject
objectAtIndex:
removeAllObjects
replaceObjectAtIndex
NSDictionary
NSDictionary dictionaryWithObjectsAndKeys
initWithObjectsAndKeys
setObject forkey
objectForkey
removeObjectForKey
setObject:obj forKey:key
NSSet
setWithObjects
[set count]
写完最后一部分协议就应该可以上手看interface builder了,哎 人艰不拆啊;
协议在类中的声明;
@protocol
方法声明
@end
@implementation 类名
类和协议中声明的方法的实现
声明协议:
@protocol ASD<NSObject>
-(void) go
@end
@interface ABC:NSObject<ASD>
@end
@implementation ABC
-(void) go
{
}
@end
@protocol ASD<NSObject>
@interface ABC:NSObject<ASD,ASF,ASG>
@end
object -c 消息
@selector delegate 这两个是最难点的了。。。
终于明白了;那比如说我用xib来做东西;那nib就是初始化里面的初始化的界面;那viewcontroller就是来获得你点击的事件的;那delegate呢 就是获得事件要具体干啥子来呢,就有delegate来做具体的业务逻辑;明白了这些应该可以上手了
推荐一个网页