dispatch_async(dispatch_get_global_queue(0, 0), ^{ //加入耗時操做 ... dispatch_async(dispatch_get_main_queue(), ^{ //更新UI操做 ... }); });
[username_text setValue:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5] forKeyPath:@"_placeholderLabel.textColor"];
多線程
//textfield的函數 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [username_text resignFirstResponder]; [password_text resignFirstResponder]; // When the user presses return, take focus away from the text field so that the keyboard is dismissed. NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height); self.view.frame = rect; [UIView commitAnimations]; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { // When the user presses return, take focus away from the text field so that the keyboard is dismissed. NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height); self.view.frame = rect; [UIView commitAnimations]; [textField resignFirstResponder]; return YES; } - (void)textFieldDidBeginEditing:(UITextField *)textField { CGRect frame = password_text.frame; int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0);//鍵盤高度216 NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeForKeyBoard" context:nil]; [UIView setAnimationDuration:animationDuration]; float width = self.view.frame.size.width; float height = self.view.frame.size.height; if(offset > 0) { CGRect rect = CGRectMake(0.0f, -offset,width,height); self.view.frame = rect; } [UIView commitAnimations]; }
iOS獲取app版本號 plist文件app
versionLabel.text = [NSString stringWithFormat:@"v%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]];
tableView的增長,刪除,刷新,更新的方法async
NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0]; //插入某一行 [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation: UITableViewRowAnimationNone]; //插入某一分區 [self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone]; //刪除某一行 [self.tableView removeRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone]; //刪除某一分區 [self.tableView removeSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone]; //刷新某一行 [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone]; //刷新某一分區 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone]; //更新某一行 [self.tableView updateRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone]; //更新某一分區 [self.tableView updateSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone]; //刷新整個tableview [self.tableView reloadData];