1. Methods with no parameter<method type> (<return type>) <method name>;+ (voID) createCarname;- (voID) createCarname;2. Methods with a single parameter<method type> (<return type>) <method name>: (<argument type>) <argument name>;+ (voID) createCarname: (Nsstring *) name;- (voID) createCarname: (Nsstring *) name;3. Methods with 2 parameters<method type> (<return type>) <method name>: (<argument type>) <argument name> <argument 2 label>: (<argument 2 type>) <argument 2 name>;+ (voID) createCarname: (Nsstring *) name withColour : (Nsstring *) colour;- (voID) createCarname: (Nsstring *) name withColour : (Nsstring *) colour; Step 4: Calling the methods1. Create a file called IOSTutorial.h and declare the following information:#import <Foundation/Foundation.h>#import "CarClass.h"int main (int argc,const char * argv[]){ @autoreleasepool { CarClass *car = [[CarClass alloc] init]; [car createCarname:@"Honda" withColour:@"Red]; [CarClass createCarname:@"Honda" withColour:@"Red"]; } return 0;}
毕竟是半道开始学习,所以有些基础性的还是记下来比较好。 这篇主要是对method的记录。 参考链接为:[http://iosprogrammingtutorials.com/objective-c-tutorial-1-how-to-declare-objective-c-methods/](http://iosprogrammingtutorials.com/objective-c-tutorial-1-how-to-declare-objective-c-methods/)
至于class method和instance method我就不记录了,这不是今天的重点,重点是method的形式。method其实就是类似,应该是很类似c里面的function,但应该还有不一样的地方,具体哪里不一样我现在还说不上来,不能系统的总结出来,等能总结出来时再记录吧。既然是按照function来理解的,那就有些熟悉了。首先要有函数名,其次是返回值和参数。当然了,这3个因素先说哪个都无所谓,不是按照重要性排名。
毕竟是半道开始学习,所以有些基础性的还是记下来比较好。这篇主要是对method的记录。参考链接为:[http://iosprogrammingtutorials.com/objective-c-tutorial-1-how-to-declare-objective-c-methods/](http://iosprogrammingtutorials.com/objective-c-tutorial-1-how-to-declare-objective-c-methods/)至于class method和instance method我就不记录了,这不是今天的重点,重点是method的形式。method其实就是类似,应该是很类似c里面的function,但应该还有不一样的地方,具体哪里不一样我现在还说不上来,不能系统的总结出来,等能总结出来时再记录吧。既然是按照function来理解的,那就有些熟悉了。首先要有函数名,其次是返回值和参数。当然了,这3个因素先说哪个都无所谓,不是按照重要性排名。
原谅我,把本该在这里现实的代码放到了文章的开头了,因为我不会使用这个编辑工具,太难用了。
---------分割线----------
- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { //return [animals count]; if(section == 0) { return 1; } else { return 3; }}-(Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw TitleForheaderInSection:(NSInteger)section{ if(section == 0) { return @"One-header"; } else { return @"Two-header"; }}-(Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw TitleForFooterInSection:(NSInteger)section{ if(section == 0) { return @"One-Footer"; } else { return @"Two-Footer"; }}最开始看到上面的3个接口,没能看明白,主要是没能找对函数名和参数,哪挨着哪啊,因为我是用c的理解去判断的,所以肯定找不对,但是对照着method的定义就理解了。况且返回值,函数名,参数这3个一起构成了method,注意看啊,从第2个参数开始还有个label,不过他是用<>来引用的,就是可有可无的,但是我看代码中大部分都有,是为了方便理解这参数是干嘛用的,卧槽,这样就可以省去在函数头前写一大段函数的参数说明了。label这个字段在c中可是没有的,使用返回值+函数名+参数一起确定一个method这在c中应该是不能够有的情况,c中只要函数名重复了都会提示redefine,根本不给你区分参数和返回值不同的机会。请别见怪啊,我在csdn上贴这么low的帖子,而且还public了。最后我想说的是,我也不知道上面的话我写的通顺不通顺,都是想起来就写敲进去了,如果不通顺的话我也不想改了。 总结
以上是内存溢出为你收集整理的objective-c中的method全部内容,希望文章能够帮你解决objective-c中的method所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)