第一次总结

一、给button设置图片


按钮一般有四种状态:“normal”,“highlight”,“selected”,“disabled”

<span style="font-family:FangSong_GB2312;font-size:18px;">[btn setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"2"] forState:UIControlStateHighlighted];
    [btn setImage:[UIImage imageNamed:@"4"] forState:UIControlStateSelected];
    [btn setImage:[UIImage imageNamed:@"3"] forState:UIControlStateDisabled];
  //  btn.enabled = NO;  //将按钮设置为禁用
 //   btn.selected = YES;//设置默认为选中状态</span>


二、对象之间的传值


对象之间的传值,关键思想是 设置属性(如果是使用代理时,则要使用弱引用),然后关键是找到对象(在对象与对象之间碰面时是最好的时机)。

eg:弱引用

<span style="font-family:FangSong_GB2312;font-size:18px;">@property (nonatomic, weak) id<DownloaderDataDelegate> delegate;</span>

三、应用程序的生命周期

UIApplicationMain函数,程序将进入AppDelegate.m,这个文件是xcode新建工程时自动生成的。下面看一下AppDelegate.m文件,这个关乎着应用程序的生命周期。

<pre name="code" class="objc"><span style="font-size:18px;"> 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
{  
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];  
    // Override point for customization after application launch.  
    self.window.backgroundColor = [UIColor whiteColor];  
    [self.window makeKeyAndVisible];  
    NSLog(@"iOS_didFinishLaunchingWithOptions");  
    return YES;  
}  
  
- (void)applicationWillResignActive:(UIApplication *)application  
{  
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.  
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.  
    NSLog(@"iOS_applicationWillResignActive");  
  
}  
  
- (void)applicationDidEnterBackground:(UIApplication *)application  
{  
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.   
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.  
    NSLog(@"iOS_applicationDidEnterBackground");  
  
}  
  
- (void)applicationWillEnterForeground:(UIApplication *)application  
{  
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.  
    NSLog(@"iOS_applicationWillEnterForeground");  
  
}  
  
- (void)applicationDidBecomeActive:(UIApplication *)application  
{  
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.  
    NSLog(@"iOS_applicationDidBecomeActive");  
  
}  
  
- (void)applicationWillTerminate:(UIApplication *)application  
{  
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.  
    NSLog(@"iOS_applicationWillTerminate");  
  
}  
</span>


 
     1、application didFinishLaunchingWithOptionos:当应用程序启动执行,应用程序启动入口,只在应用程序启动时执行一次。若用户直接启动,lauchOptions内无数据,若通过其他方式启动应用,lauchOptions包含对应方式的内容。 

     2、applicationWillResignActive:在应用程序将要由活动状态切换到非活动状态时候,要执行的委托调用,如 按下 home 按钮,返回主屏幕,或全屏之间切换应用程序等。

     3、applicationDidEnterBackground:在应用程序已进入后台程序时,要执行的委托调用。

     4、applicationWillEnterForeground:在应用程序将要进入前台时(被激活),要执行的委托调用,刚好与applicationWillResignActive 方法相对应。

     5、applicationDidBecomeActive:在应用程序已被激活后,要执行的委托调用,刚好与applicationDidEnterBackground 方法相对应。

     6、applicationWillTerminate:在应用程序要完全推出的时候,要执行的委托调用,这个需要要设置UIApplicationExitsOnSuspend的键值。 

     

初次启动:

2013-05-24 20:20:31.550 LifeIOS[451:c07] iOS_didFinishLaunchingWithOptions

2013-05-24 20:20:31.551 LifeIOS[451:c07] iOS_applicationDidBecomeActive


按下home键:

2013-05-24 20:22:17.349 LifeIOS[451:c07] iOS_applicationWillResignActive

2013-05-24 20:22:17.350 LifeIOS[451:c07] iOS_applicationDidEnterBackground


点击程序图标进入:

2013-05-24 20:22:56.913 LifeIOS[451:c07] iOS_applicationWillEnterForeground

2013-05-24 20:22:56.914 LifeIOS[451:c07] iOS_applicationDidBecomeActive

 

程序中没有设置UIApplicationExitsOnSuspend的值,程序不会彻底退出。

 

三、页面的生存周期



1、用属性中getter方法获取self.view(弹出模态视图和push到导航视图也是属于比较隐蔽的getter方法获取self.view)

一旦遇到getter方法获取self.view如果是空(第一次运行一般都是空)则进入loadview加载view(永远不要手动调用它
如果想要自定义self.view的话,只有一次机会) 然后再进入viewDidload中。


2、页面的生存周期如上图

四、同步&异步

1、同步


2、异步



五、同步下载&异步下载

1、同步下载(一般只用于下载比较小的数据)

a、NSString下载文本类型数据

 NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
    NSString *htmlStr = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%@", htmlStr);


b、NSData下载任意数据类型

 NSData *data = [NSData dataWithContentsOfURL:url];
    NSString *str0 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"%@", str0);

c、使用 sendAsynchronousRequest方法下载

NSURLResponse *response1 = [[NSURLResponse alloc] init];
NSData *data2 = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com/"]] returningResponse:&response1 error:nil];
NSString *str3 = [[NSString alloc] initWithData:data2 encoding:NSUTF8StringEncoding];
NSLog(@"str3: %@", str3);




2、异步下载

a、sendAsynchronousRequest方法异步下载

[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com/"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    NSLog(@"下载完成。。。");
}];
NSLog(@"程序结束");


b、 使用NSURLConnectionDataDelegate (使用协议)

挂出协议,协议指针指向,实现协议中的四个必须实现的方法

可以对下载协议进行封装。(感觉很是牛逼,我还没有达到那个水平、、、、)


六、协议


定义指针id的时候可以对其进行限定(这样指针就只能指向实现了协议的对象)

eg:

@property (nonatomic, strong) Dog *dog;
@property (nonatomic, strong) id something;
@property (nonatomic, strong) id<BiteDelegate> delegate;


两个对象通过指针指向不同的方法


七、解析

1、解析josn

josn解析比较简单一般无压力

2、解析xml

相对比较复杂需要引入开源的代码


<span style="font-size:18px;"> NSString *string = @"<note>\
    <to>George</to>\
    <from>John</from>\
    333<heading>Reminder</heading>\
    444<body>Don't forget the meeting!</body>\
    </note>";
    
    
    NSDictionary *dict = [NSDictionary dictionaryWithXMLString:string];
    NSLog(@"%@", dict);
    
    NSData *data = [NSData dataWithContentsOfFile:string];
    NSDictionary *dict2 = [NSDictionary dictionaryWithXMLData:data];
    NSLog(@"%@", dict2);
</span>

/* 结果

     {

     "__name" = note;

     "__text" =     (

     333,

     444

     );

     body = "Don't forget the meeting!";

     from = John;

     heading = Reminder;

     to = George;

     }

     */

3、解析HTML

最复杂的也需要引入开源代码


现根据findChildrenWithAttribute方法(根据属性找到子节点)

再根据节点名查找子节点

<span style="font-size:18px;">NSArray *carray = [bodyNode findChildrenWithAttribute:@"class" matchingName:@"trans-container" allowPartial:YES];
    NSLog(@"---%@",carray);
    HTMLNode *ulNode = [carray[0] findChildTag:@"ul"];
    HTMLNode *liNode = [ulNode findChildTag:@"li"];
    NSLog(@"%@",[liNode contents]);</span>

八、UItableView


cell的重用问题,协议的问题。。。感觉珊哥写的很是复杂。需要时间慢慢消化



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值