小结

1.按钮的图片设置

按钮的图片有4种状态,Normal,Highlighted,Selected,Disabled

按钮可以有背景图和按钮图片两个图。 

 

2.viewDidLoad的调用时机

view的加载是延迟加载,要使用的时候才加载。

用getter获取self.view时,执行以下操作:


所有的控件或者视图想要显示,必须要addSubview到一个已经显示的视图上

 

//异步操作,在里面有调用addSubview

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion     

 

- (void)loadView;

在这里创建UIView对象,并设置给self.view

永远不要手动调用

可以在这里自定义self.view,不要在此方法以外的地方改变self.view

 

 

3.UIViewController生命周期

第一个页面消失要等到第二个页面显示之后。

 

 

4.头文件循环引用解决办法

当两个头文件要相互引用的时候,会造成循环引用。
将其中一个头文件中的类用 @class 引入, 告诉编译器已经定义了这个类,在真正使用的时候,还是要把头文件引入到 .m 文件里。
 
 

5.对象之间的数据传递

可以通过属性传值,主要是找到对象,还要想办法让两者碰面。

 
 
6.下载方法总结
同步:
1.简单的网页下载

NSString *str = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

2.数据下载

NSData *data = [NSData dataWithContentsOfURL:url];

3.请求连接类同步下载方法

+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;

异步:

1.请求连接类异步下载方法

+ (void)sendAsynchronousRequest:(NSURLRequest*) request  queue:(NSOperationQueue*) queue  completionHandler:(void (^)(NSURLResponse* response, NSData* data, NSError* connectionError)) handler;

2.请求连接类初始化方法异步下载

- (instancetype)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)startImmediately;

 - (instancetype)initWithRequest:(NSURLRequest *)request delegate:(id)delegate;  这个要用 start 方法才开始

 + (NSURLConnection*)connectionWithRequest:(NSURLRequest *)request delegate:(id)delegate;

 设置的delegate对象要实现协议<NSURLConnectionDataDelegate>

常用协议方法:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;

 

7.协议

只有方法声明,没有实现,可以被任何类实现。
 
注意: 定义指针的时候,为了避免引用循环,不要用retain/strong强引用
 
 
8.JSON/XML/HTML数据解析
JSON数据是字符串,可以转化成OC的字典、数组、数字、字符串、BOOL值。

+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error;

XML是字符串,解析后是一个字典。

HTML 是静态的描述语言,可以看做受限的XML文档,标签受限,语法凌乱。
 
 
9.UITableView
默认情况下,TableView有头部和尾部,每个section也都有头部和尾部

//可以设置Tableview的头部和尾部

@property (nonatomic, retain) UIView *tableHeaderView;                          

@property (nonatomic, retain) UIView *tableFooterView;

UIView *headerview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 10)];  只有高度值设置才有效

 

//设置section头部和尾部的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

 

//设置section头部和尾部样子

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;

 

//设置section头部和尾部的标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

 

 

 
 

 

 

posted @ 2014-08-16 16:29  couse  阅读(223)  评论(0)    收藏  举报