ios开发使用extern访问全局变量:
- extern NSString *url; //这里使用到extern c关键字,表示这个变量已经声明,只是引用。
- url = [[NSString alloc] initWithFormat:@"http://www.hbcfg.net"];//指针类型;需要alloc
- extern int count;
- count = 0;//非指针类型
对于static修饰的变量
#import "SecondViewController.h"
static int count;
@implementation SecondViewController;
.......
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"viewWillAppear is %d",count);
count+=1;
}
这样你每进入一次界面就会发现count加1
除非程序完全退出重启,count才会清除,objective-c中用static修饰的变量和java中的静态变量是有区别的,其不能通过类名直接访问,当然你想直接访问也是能实现的在.m中写一个类方法反回count就行了,而且其作用域是其本类,不能扩展到其他类中
1. Give us example of what are delegate methods and whatare data source methods of uitableview.
1> 代理方法:返回tableView每行的高度、监听tableView每行的选中
2> 数据源方法:返回tableView数据的组数和行数、每行显示什么数据
2. What are commonly used NSObject class methods?
NSObject常见的类方法有:alloc、new、description(类方法返回类名,对象方法返回类名+内存地址,nslog需要获取更多信息需要重写该方法)等