viewDidUnload方法
(loadView/nib文件)来加载view到内存 ——>viewDidLoad函数进一步初始化这些view ——>内存不足时,调用viewDidUnload函数释放views —->当需要使用view时有回到第一步,如此循环。
- (void)viewDidLoad
is not called when the view controller is loaded; it is called when the view controller‘s view is loaded.
操作button上的title,不要直接去操作label
不应该button.titleLabel.text = @"test";
这样越过了button的封装。
应该使用 [button setTtile: forState:]的方法。
NSJSONSerialization 可以用来转换json 和 object
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
options:NSJSONWritingPrettyPrinted // Pass 0 if you don‘t care about the readability of the generated string
error:&error];
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
可以把一个dict To jsonstring
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
可以把一个json字符串 转为dict
//根据 segue Identifier跳转界面
[self performSegueWithIdentifier:@"GotoTwo" sender:self];
//以modal 方式跳转
[self presentModalViewController:nil animated:YES];
//压进一个viewcontroller
[self.navigationController pushViewController:nil animated:YES];
//弹出一个viewcontroller 相当与返回上一个界面
[self.navigationController popViewControllerAnimated:YES];
// 以 modal跳转的返回方法
[self dismissModalViewControllerAnimated:YES];
Modal segues take over the whole screen, so any navigation bars, tool bars, or tab bars that are in the presenting controller will be covered up. If you want a navigation bar on this modal controller, you‘ll need to add one specifically to it, and add any buttons you want to that new navigation bar (or tool bar). If you don‘t want to do this, then don‘t present it modally, do a push to it.
storyboard的unwind segue
- (IBAction)unwindSegueToIndexViewController:(UIStoryboardSegue *)segue {
}
exit 的连线
可以快速返回某一个ViewController
Restoration identifier 和 reuse identifier
前者是恢复用的ID
后者是cell重复利用的ID
-(BOOL) application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
return YES;
}
-(BOOL) application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
return YES;
}
- (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder
{
NSDate *date = [NSDate date];
NSTimeInterval sec = [date timeIntervalSinceNow];
NSDate *currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec];
//设置时间输出格式:
NSDateFormatter *df = [[NSDateFormatter alloc] init ];
[df setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"];
NSString *na = [df stringFromDate:currentDate];
[coder encodeObject:na forKey:@"lastShutdownTime"];
}
- (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder
{
NSString * currentTime = [coder decodeObjectForKey:@"lastShutdownTime"];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"上次关闭时间"
message:currentTime
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
下面是可以设置动画效果的属性:
- frame
- bounds
- center
- transform
- alpha
- backgroundColor
- contentStretch
不建议直接向nextResponder发送消息,这样可能会漏掉父类对这一事件的其他处理。