aBigRoybot

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

本人新手, 学了几天ios, 开始自己写一点东西, 主旨是为了自己巩固加强, 一方面也好有个记录, 好看看自己曾经stuck的问题, 另一方面, 本着分享, 开源的精神, 献丑了.

我会全部靠理解, 记忆把我实现的功能手动敲一边, 所以不保证可以运行, 但是demo里面的一定可以运行.

demo介绍:

我在初期是准备把所有控件全部实现一边, 后面发现有很多是雷同, 关于控件属性的熟悉, 这种遍历可能起不到太大作用, 所以就挑了几个主要的实现了一下. 所以有些class是空的.

主要的, Table View, Navigation View, Tab Bar View, Tool Bar View, Image View, Web View, Pick View, 还有一些小的什么progress, slider, switch.

a] rootController就是一个navigation bar, 不要纠结于什么IB了, 直接代码建立这个navigation是最方便快捷的. 在appDelegate里面加上

self.window = [[UIWindow alloc] initWithFram: [UIScreen mainWindow] bounds];
RootView * rootView = [[RootView alloc] init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootController: rootViiew]; //3rd
self.window.rootController = nav;
[self.window makeKeyandVisible];

如果你在IB里面定义了nav, 记得就不用  3rd那一行了, 直接关联就可以了.

nav的root view controller是一个table view controller, 关于这个controller的功能描述:

a) 实现所有控件分类后的list展示.

b) 点击particular cell进入对应的模块.

因此, 要实现的方面有2个:

a) 对table view 数据的绑定.

b) datasource和delegate的定义.

关于数据的绑定, 我是这样实现的:

定义了一个NSArray, 里面存的是一组Dictionary, 每个Dictionary有这样两个key: Title, control.

  title是在table view上显示出来的东西.

  control就是进入每个cell之后显示的view.

self.menuList = [[NSMutableArray alloc] init];
TextViewCtrl * textViewCtrl = [[TextViewCtrl allco] init];
[menuList addObjet: [NSDictionary dictionaryWithValuesAndKeys: @"Text View", @"Title", textViewCtrl, @"Control"];
//以此类推

然后就没什么新奇的了, 在didSelectRowAtIndexPath里面把每个viewController push就可以了.

    [self.navigationControllerpushViewController: [toPush valueForKey: @"Control"] animated: YES];

NOTE: 在iOS5里面, 给leftBarButtonItem重新定义不用那么麻烦了, 写一个UIBarButton就可以了, 箭头不会消失.

UIBarButtonItem * back = [[UIBarButtonItem alloc] init];
back.title = @"Back";
self.navigation.backBarButtonItem = back; //注意这里, 赋给的不是leftBarButton, 虽然他们在位置上是一样

接下来我写了TextView(这个还没完成...关于archive的功能还没写..有点卡壳)

textView很容易写, 但是有一点, textView基本上是整个屏幕的, 所以点击屏幕上键盘外的地方让键盘缩回去在这里不适用, 需要加个button让键盘缩回去, 刚好可以在这个button里面archive.

再来是Tool Bar, Pick View, Slider, Switch, SegmentedControl.

这几个控件的alpha, enable属性可以达到那种, 不可点击的灰色效果.

toolbar的style比较重要, 另外要了解UIBarButtonSystemItem这个枚举(是的, 这事一个枚举, 虽然你可以看到initWithBarButtonSystemItem以这个枚举变量为参数), 这个枚举就可以生成那些toolbar上很小很小的图标了.

后来是Web View, 就一个方法, loadRequest, load的是一个textfield的text.  另外记得调整networkActivityIndicator的状态.(就是status bar上运营商旁边的那个小菊花). 

imageView的slider主要是用的AnimationImages这个.

附上demo:

http://115.com/file/bhutgigr#
Review.zip

 

posted on 2011-11-14 02:51  aBigRoybot  阅读(771)  评论(0编辑  收藏  举报