1.UIViewController UIView的关系。

UIView是视图,UIViewController是视图控制器,两者之间是从属关系,当创建一个UIViewController的时候,一般UIViewController都会自带一个UIView就是UIViewController.UIView,一般我写不用nib创建的视图都是继承自UIViewController.

2.下面是讲的UITableViewController和UIViewController之间的区别

UITableViewController继承自UIViewController,但是initWithNibName:bundle:方法的行为是不一样的。普通的UIViewController如果nibName参数是nil,则自动载入和自己类名相同的xib文件。而UITableViewController遇到nibName为nil时,却不加载xib文件,而是创建一个空的table view。所以,对于UITableViewController来说,如果使用了xib文件,则必须写出完整xib文件名,才能正确创建。

因此,当使用了xib时,UITableViewController不能使用这样的方式创建:

[[TableViewController alloc] init];
[[TableViewController alloc] initWithNibName:nil bundle:nil];

另外,UITableViewController的view属性和tableView属性是联动的,无法自己改变此种关联。就是说,UITableViewController的顶级view必须是一个tableView,没法自己在loadView中创建一个view,然后再加入一个tableView。所以,如果想自己控制页面的布局,必须继承自UIViewController,而不是UITableViewController。

3.UIview 函数的addsubview

addsubview其实就是相当于又retain一次类实例。所以原来alloc的控件就可以release了,控件的引用还是1.

NSDirectory 类的setObject forKey函数也是一样,添加进directory中的实例相当于又retain了,然后我们就可以把原来的release掉了。所以今天因为不懂的这个原理,就又一行代码看了好久而不理解。我把一个类变量声明为字典类型,这个字典后面又添加了一个array类型的局部变量,后面出了作用阈还在往array中间添加变量。现在明白了。

4.

原来就想实现这个功能,实现点击屏幕的任意位置来实现关闭虚拟键盘的功能,就是增加一个手势的识别,添加select函数就可以了

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizeralloc] initWithTarget:selfaction:@selector(handleSwipe:)];

    swipe.direction = UISwipeGestureRecognizerDirectionDown;

    swipe.numberOfTouchesRequired = 1;

    [_inputViewaddGestureRecognizer:swipe];

    [swipe release];

posted on 2013-09-11 15:00  暴走路人甲  阅读(638)  评论(0编辑  收藏  举报