NJ 学习点滴积累
1.ios中app設(shè)置的添加
http://blog.csdn.net/bihailantian1988/article/details/8332972
利用新建setting bundle 實(shí)現(xiàn)
2.?阻止iOS設(shè)備鎖屏
http://www.2cto.com/kf/201111/109789.html
[UIApplication shareApplication] setIdleTimerDisabled:YES];
3.兩個(gè)view 交換位置
a.最原始的一種,用addview、和removefromsuperview 進(jìn)行修改
??self.firstView = [[UIViewalloc]initWithFrame:CGRectMake(0,100,200,200)];
? ? _firstView.backgroundColor = [UIColoryellowColor];
? ? UILabel *textlabel = [[UILabelalloc]initWithFrame:CGRectMake(0,100,200,40)];
? ? textlabel.text = @"這是第一個(gè)Firstview";
? ? [_firstView addSubview:textlabel];
? ? UIButton *btn1 = [UIButtonbuttonWithType:UIButtonTypeCustom];
? ? btn1.frame = CGRectMake(0,0,80,60) ;
? ? [btn1 setTitle:@"進(jìn)入"forState:UIControlStateNormal];
? ? [btn1 addTarget:selfaction:@selector(jumpinto:)forControlEvents:UIControlEventTouchUpInside];
? ? [btn1 setBackgroundColor:[UIColorblueColor]];
? ? [_firstView addSubview:btn1];
? ??self.secondView = [[UIViewalloc]initWithFrame:CGRectMake(0,100,200,200)];
? ? _secondView.backgroundColor = [UIColorredColor];
? ? UILabel *textlabel1 = [[UILabelalloc]initWithFrame:CGRectMake(0,100,200,40)];
? ? textlabel1.text = @"這是第二個(gè)Secondview";
? ? [_secondView addSubview:textlabel1];
? ? UIButton *btn2 = [UIButtonbuttonWithType:UIButtonTypeCustom];
? ? btn2.frame = CGRectMake(0,20,80,60) ;
? ? btn2.backgroundColor = [UIColorblueColor];
? ? [btn2 setTitle:@"返回"forState:UIControlStateNormal];
? ? [btn2 addTarget:selfaction:@selector(back:)forControlEvents:UIControlEventTouchUpInside];
? ? [_secondView addSubview:btn2];
//添加第一個(gè)view
? ? ? ? [self.view addSubview:_firstView];
}
//加上第二個(gè)view 以覆蓋第一個(gè)
-(void)jumpinto:(id)sender
{
?? ? ? [self.view addSubview:_secondView];
}
//移除第二個(gè)view,顯示第一個(gè)
-(void)back:(id)sender
{
? ? [self.secondViewremoveFromSuperview];
? ??NSLog(@"self.secondView = %@",self.secondView);
}
b.用Uivew 自帶的方法??[UIViewtransitionFromView:self.secondViewtoView:self.firstViewduration:0.5?
? ? ? ?options:UIViewAnimationOptionTransitionFlipFromLeftcompletion:^(BOOL finished) {
?? ? ? ?
? ? }];
4.兩個(gè)控制器間的傳值
a.屬性傳值
b.代理傳值 ?(注意 設(shè)置代理的對(duì)象有無發(fā)生改變)
c. block 傳值
d.通知傳值
e.單例傳值
5. 對(duì)于oxFF & i,i為一個(gè)int類型的數(shù)
http://jingyan.baidu.com/article/215817f7d6f9881eda1423f9.html
6.對(duì)于uitableview 的滑動(dòng)刪除步驟
a.?
//先要設(shè)Cell可編輯
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? returnUITableViewCellEditingStyleDelete;
}
//修改編輯按鈕文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? return @"刪除";
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? if (editingStyle ==UITableViewCellEditingStyleDelete)
? ? {
? ? ? ? _currentSelectIndexpath = indexPath;
? ? ? ? UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:nilmessage:@"確定刪除該聯(lián)系人的通話記錄" delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"確定",nil];
? ? ? ? [alertView show];
? ? }
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{1.刪除數(shù)據(jù)庫
2.刪除_dataArray中數(shù)據(jù)
3.刪除row?
[self.detailTableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObject:_currentSelectIndexpath]withRowAnimation:UITableViewRowAnimationLeft];
4.刷新tableview
}
7. 對(duì)于storyboard約束常見錯(cuò)誤
http://www.cocoachina.com/applenews/devnews/2013/1203/7462.html
注意T-bars仍然是橘黃色的。這意味這你的布局沒有完成;自動(dòng)布局沒有足夠的約束條件計(jì)算出視圖的位置和大小。解決辦法便是增加更多約束,直到他們變藍(lán)。
a.約束條件不全 ?(比如只有上約束+寬高 ,無法確定 控件的位置)
b. 約束出錯(cuò) (約束的數(shù)值有錯(cuò)、多次約束同一個(gè))
8. 對(duì)于uitableview 的cell自定義
在繪制cell的時(shí)候,展示數(shù)據(jù)放到CustomCell中去,不要放到cellForRowAtIndexPath方法中,
CustomCell *cell =?[tableView?dequeueReusableCellWithIdentifier:CellIdentifier];
[cell ?setupCellWithModel:contactinfo Model類 ? ? ?indexPath:indexPath];
return cell;
}
9. 對(duì)于一些通知名,常量的定義最好放到一個(gè)專門的#define 文件中,利于管理
#define kTestPhoneNumber @"11230801178"
10. 對(duì)于模擬器調(diào)試,定義一個(gè)宏
http://www.2cto.com/kf/201309/243211.html
#define USE_TEST 1
//調(diào)試模式
#if DEBUG
#if USE_TEST
? ? [[COCall?shard]?dialSuccess];
#else
#endif
#else
#endif
11. 對(duì)于數(shù)據(jù)庫DB的操作,最好放到一個(gè)單例類中,讓所有數(shù)據(jù)庫操作的入口都從這個(gè)單例中進(jìn),容易控制
12.給uitableview 設(shè)置長(zhǎng)按手勢(shì)
??UILongPressGestureRecognizer *longPressGr = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPressCell:)];
? ? ? ? longPressGr.minimumPressDuration = 1;
? ? ? ? [self.tableViewaddGestureRecognizer:longPressGr];
#pragma mark - Gesture
- (void)longPressCell:(UILongPressGestureRecognizer *)gesture
{
? ? if (gesture.state ==UIGestureRecognizerStateBegan)
? ? {
? ? ? ? CGPoint point = [gesture locationInView:self.tableView];
? ? ? ? NSIndexPath *indexPath = [self.tableViewindexPathForRowAtPoint:point];
? ? ? ? if (indexPath == nil)
? ? ? ? {
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? //長(zhǎng)按彈框
? ? ? ? }
? ? }
}
13. 對(duì)于一些基本的UI 操作盡量封裝,如:navigationBar、statusBar隱藏之類的,
- (void)hideNavigationBarWithAnimation
{
//隱藏、animation動(dòng)畫操作
}
14. 一般的UITabbar的代理UITabBarControllerDelegate
設(shè)置代理
? ?self.tabBarController.delegate =self;
? ??self.navigationController.delegate =self;
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewControlle
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
15. navigationbar 的代理方法
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
16. 對(duì)于Segue的使用
a.在storyboard上面連線,給Storyboard Segue ?Identifier:SegueName?
b. 在對(duì)應(yīng)VC里的代碼
- (void)searchBtnPress:(id)sender
{
? ? [selfperformSegueWithIdentifier:ContactsPushSearchSeguesender:nil];
}
sender為跳轉(zhuǎn)的控件:UIButton、UITableViewCell
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
? ? if ([segue.identifierisEqualToString:ContactsPublicInfoSegue])
? ? {
? ? ? ? ContactsInfoViewController *info = segue.destinationViewController;
//傳遞數(shù)據(jù)
? ? ? ? info.contactType =ContactsInfoTypePublic;
? ? }
? ? elseif ([segue.identifierisEqualToString:ContactsPushPublicSearchSegue])
? ? {
? ? ? ? ContactSearchVC *sv = segue.destinationViewController;
? ? }
}
15. uitableview右側(cè)索引
http://poolo.iteye.com/blog/1704922
設(shè)置sectionIndex
-(NSArray?*)sectionIndexTitlesForTableView:(UITableView?*)tableView;
此時(shí)是默認(rèn)對(duì)應(yīng) 順序?qū)?yīng) sectionIndex根據(jù)順序?qū)?yīng) 到section
?
修改sectionIndex對(duì)應(yīng)
- (NSInteger)tableView:(UITableView?*)tableView sectionForSectionIndexTitle:(NSString?*)title atIndex:(NSInteger)index{
通過傳入的傳入每個(gè)sectionIndex的title,index 來設(shè)置這個(gè)sectionIndex 對(duì)應(yīng)的section。
16.對(duì)于uitableviewcell 設(shè)置滑動(dòng)的位置
setContentOffset
[self.tableViewsetContentOffset:CGPointMake(0,localContent)];
17. ?UITextField的代理方法 ?UITextfieldDelgate
- (void)textFieldDidBeginEditing:(UITextField *)textField;?
- (void)textFieldDidEndEditing:(UITextField *)textField;
18.uilabel的尺寸frame根據(jù)文本內(nèi)容進(jìn)行計(jì)算
?CGSize ansize = [answerLabel.textsizeWithFont:[UIFontsystemFontOfSize:15]constrainedToSize:CGSizeMake(280,MAXFLOAT)lineBreakMode:NSLineBreakByWordWrapping];
answerLabel.frame = CGRectMake(0,0,固定寬,ansize.height)
19 .對(duì)于延遲加載問題
a.
單利GlobalData中 ? ?.h 文件中屬性NSArray *students;
- (void)reloadStudentData; //供外部使用
在?"GlobalData.m" 中
BOOL isLoadStudentsData; ?//標(biāo)志是否加載過數(shù)據(jù)(如果沒有變化,整個(gè)app 只要加載一次)NSArray * StudentDataInside; ? //內(nèi)部使用
- (NSArray *) students
{
if(isLoadStudentData){
return StudentDataInside;
}else{
[StudentDataInside removeAllObjects];
//方法獲取數(shù)據(jù) StudentData
[ ? 方法調(diào)用 ?];
改變標(biāo)志位
isLoadStudentData = YES; ?//說明加載過
return ?studentDataInside;
}
}
//當(dāng)需要刷新數(shù)據(jù)時(shí)候
- (void)reloadStudentData
{
改變標(biāo)志位
isLoadStudentData = NO; ?//說明加載過
[studentDataInside removeAllObjects];}
b.當(dāng)數(shù)據(jù)改變時(shí)候,要刷新某個(gè)界面時(shí)候,(判斷當(dāng)前界面時(shí)候是要刷新的界面,if YES,刷新; if NO , 給個(gè)刷新標(biāo)志,當(dāng)目標(biāo)界面載入的時(shí)候再去刷新)
通知調(diào)用的方法
BOOL isViewShow; ?//當(dāng)前界面標(biāo)志
[NSNotificationCenter ?DefaultCenter] addObserver : selector : ?name: ?];
- (void)viewWillAppear
{
self.isViewShow?=?YES;
if(_isRefrshSearchResult){
//刷新操作
}
}
- (void)loadDataDone
{
if(isViewShow ){
//刷新操作
}else{
_isRefrshSearchResult = YES;
}
}
20. 對(duì)于多次點(diǎn)擊只執(zhí)行最后一次操作
http://blog.csdn.net/fengsh998/article/details/11112885
//取消延遲時(shí)間之前的操作
??[NSObjectcancelPreviousPerformRequestsWithTarget:self];
? ?[selfperformSelector:@selector(searchDelay:)withObject:text afterDelay:kDelayTime];
21. 對(duì)于線程:NSObject、NSThread、NSOperationQueue、GCD區(qū)別
如果想取消已經(jīng)執(zhí)行的線程:NSThread、NSopeartionQueue的cancel方法,只能立馬改變這個(gè)線程的標(biāo)志位([NSThread currentThread].isCancel)屬性,并不能立即取消到線程的操作;所以要在線程的操作中加上標(biāo)志位判斷來強(qiáng)制盡快的結(jié)束掉線程
對(duì)于多個(gè)線程共享資源的爭(zhēng)奪問題:
記得加上同步鎖/、atomic原子屬性
NSThr
22.友盟統(tǒng)計(jì)
http://dev.umeng.com/analytics/ios/quick-start
23. sqlite 的觸發(fā)器使用
/*
當(dāng)T_EC_ADDR 中的name一列進(jìn)行update 操作,就會(huì)觸發(fā)執(zhí)行)update T_EC_ADDR set IS_NAME_CHANGE = 1 where NAME = new.NAME and new.NAME != old.NAME;?
一個(gè)事件的產(chǎn)生影響了另一個(gè)事件執(zhí)行
*/
CREATE TRIGGER nameChangeTrigger AFTER update of NAME ON T_EC_ADDR?
BEGIN
? update T_EC_ADDR set IS_NAME_CHANGE = 1 where NAME = new.NAME and new.NAME != old.NAME;?
end
24.?
總結(jié)
- 上一篇: python图像计数_计算机视觉:利用O
- 下一篇: Boostrap3 datetimepi