日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NJ 学习点滴积累

發布時間:2024/3/24 编程问答 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NJ 学习点滴积累 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.ios中app設置的添加

http://blog.csdn.net/bihailantian1988/article/details/8332972

利用新建setting bundle 實現


2.?阻止iOS設備鎖屏

http://www.2cto.com/kf/201111/109789.html

[UIApplication shareApplication] setIdleTimerDisabled:YES];


3.兩個view 交換位置

a.最原始的一種,用addview、和removefromsuperview 進行修改

??self.firstView = [[UIViewalloc]initWithFrame:CGRectMake(0,100,200,200)];

? ? _firstView.backgroundColor = [UIColoryellowColor];

? ? UILabel *textlabel = [[UILabelalloc]initWithFrame:CGRectMake(0,100,200,40)];

? ? textlabel.text = @"這是第一個Firstview";

? ? [_firstView addSubview:textlabel];

? ? UIButton *btn1 = [UIButtonbuttonWithType:UIButtonTypeCustom];

? ? btn1.frame = CGRectMake(0,0,80,60) ;

? ? [btn1 setTitle:@"進入"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 = @"這是第二個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];

//添加第一個view

? ? ? ? [self.view addSubview:_firstView];

}

//加上第二個view 以覆蓋第一個

-(void)jumpinto:(id)sender

{

?? ? ? [self.view addSubview:_secondView];

}

//移除第二個view,顯示第一個

-(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.兩個控制器間的傳值

a.屬性傳值

b.代理傳值 ?(注意 設置代理的對象有無發生改變)

c. block 傳值

d.通知傳值

e.單例傳值

5. 對于oxFF & i,i為一個int類型的數

http://jingyan.baidu.com/article/215817f7d6f9881eda1423f9.html

6.對于uitableview 的滑動刪除步驟

a.?

//先要設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:@"確定刪除該聯系人的通話記錄" delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"確定",nil];

? ? ? ? [alertView show];

? ? }

}

#pragma mark - UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

1.刪除數據庫

2.刪除_dataArray中數據

3.刪除row?

[self.detailTableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObject:_currentSelectIndexpath]withRowAnimation:UITableViewRowAnimationLeft];

4.刷新tableview

}


7. 對于storyboard約束常見錯誤

http://www.cocoachina.com/applenews/devnews/2013/1203/7462.html

注意T-bars仍然是橘黃色的。這意味這你的布局沒有完成;自動布局沒有足夠的約束條件計算出視圖的位置和大小。解決辦法便是增加更多約束,直到他們變藍。

a.約束條件不全 ?(比如只有上約束+寬高 ,無法確定 控件的位置)

b. 約束出錯 (約束的數值有錯、多次約束同一個)


8. 對于uitableview 的cell自定義

在繪制cell的時候,展示數據放到CustomCell中去,不要放到cellForRowAtIndexPath方法中,

  • -?(UITableViewCell?*)tableView:(UITableView?*)tableView?cellForRowAtIndexPath:(NSIndexPath?*)indexPath ?
  • {

    CustomCell *cell =?[tableView?dequeueReusableCellWithIdentifier:CellIdentifier];

    [cell ?setupCellWithModel:contactinfo Model類 ? ? ?indexPath:indexPath];

    return cell;

    }

    9. 對于一些通知名,常量的定義最好放到一個專門的#define 文件中,利于管理

    #define kTestPhoneNumber @"11230801178"


    10. 對于模擬器調試,定義一個宏

    http://www.2cto.com/kf/201309/243211.html

    #define USE_TEST 1

    //調試模式

    #if DEBUG

    #if USE_TEST

    ? ? [[COCall?shard]?dialSuccess];

    #else

    #endif


    #else

    #endif

    11. 對于數據庫DB的操作,最好放到一個單例類中,讓所有數據庫操作的入口都從這個單例中進,容易控制


    12.給uitableview 設置長按手勢

    ??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

    ? ? ? ? {

    ? ? ? ? ? ? //長按彈框

    ? ? ? ? }

    ? ? }

    }


    13. 對于一些基本的UI 操作盡量封裝,如:navigationBar、statusBar隱藏之類的,

    - (void)hideNavigationBarWithAnimation

    {

    //隱藏、animation動畫操作

    }


    14. 一般的UITabbar的代理UITabBarControllerDelegate

    設置代理

    ? ?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. 對于Segue的使用

    a.在storyboard上面連線,給Storyboard Segue ?Identifier:SegueName?

    b. 在對應VC里的代碼

    - (void)searchBtnPress:(id)sender

    {

    ? ? [selfperformSegueWithIdentifier:ContactsPushSearchSeguesender:nil];

    }

    sender為跳轉的控件:UIButton、UITableViewCell

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

    {

    ? ? if ([segue.identifierisEqualToString:ContactsPublicInfoSegue])

    ? ? {

    ? ? ? ? ContactsInfoViewController *info = segue.destinationViewController;

    //傳遞數據

    ? ? ? ? info.contactType =ContactsInfoTypePublic;

    ? ? }

    ? ? elseif ([segue.identifierisEqualToString:ContactsPushPublicSearchSegue])

    ? ? {

    ? ? ? ? ContactSearchVC *sv = segue.destinationViewController;

    ? ? }

    }


    15. uitableview右側索引

    http://poolo.iteye.com/blog/1704922

    設置sectionIndex

    -(NSArray?*)sectionIndexTitlesForTableView:(UITableView?*)tableView;

    此時是默認對應 順序對應 sectionIndex根據順序對應 到section

    ?

    修改sectionIndex對應

    - (NSInteger)tableView:(UITableView?*)tableView sectionForSectionIndexTitle:(NSString?*)title atIndex:(NSInteger)index{

    通過傳入的傳入每個sectionIndex的title,index 來設置這個sectionIndex 對應的section。


    16.對于uitableviewcell 設置滑動的位置

    setContentOffset

    [self.tableViewsetContentOffset:CGPointMake(0,localContent)];


    17. ?UITextField的代理方法 ?UITextfieldDelgate

    - (void)textFieldDidBeginEditing:(UITextField *)textField;?

    - (void)textFieldDidEndEditing:(UITextField *)textField;


    18.uilabel的尺寸frame根據文本內容進行計算

    ?CGSize ansize = [answerLabel.textsizeWithFont:[UIFontsystemFontOfSize:15]constrainedToSize:CGSizeMake(280,MAXFLOAT)lineBreakMode:NSLineBreakByWordWrapping];

    answerLabel.frame = CGRectMake(0,0,固定寬,ansize.height)


    19 .對于延遲加載問題

    a.

    單利GlobalData中 ? ?.h 文件中屬性NSArray *students;

    - (void)reloadStudentData; //供外部使用



    在?"GlobalData.m" 中

    BOOL isLoadStudentsData; ?//標志是否加載過數據(如果沒有變化,整個app 只要加載一次)

    NSArray * StudentDataInside; ? //內部使用

    - (NSArray *) students

    {

    if(isLoadStudentData){

    return StudentDataInside;

    }else{

    [StudentDataInside removeAllObjects];

    //方法獲取數據 StudentData

    [ ? 方法調用 ?];

    改變標志位

    isLoadStudentData = YES; ?//說明加載過

    return ?studentDataInside;

    }

    }


    //當需要刷新數據時候

    - (void)reloadStudentData

    {

    改變標志位

    isLoadStudentData = NO; ?//說明加載過

    [studentDataInside removeAllObjects];

    }


    b.當數據改變時候,要刷新某個界面時候,(判斷當前界面時候是要刷新的界面,if YES,刷新; if NO , 給個刷新標志,當目標界面載入的時候再去刷新)

    通知調用的方法

    BOOL isViewShow; ?//當前界面標志


    [NSNotificationCenter ?DefaultCenter] addObserver : selector : ?name: ?];

    - (void)viewWillAppear

    {

    self.isViewShow?=?YES;

    if(_isRefrshSearchResult){

    //刷新操作

    }

    }

    - (void)loadDataDone

    {

    if(isViewShow ){

    //刷新操作

    }else{

    _isRefrshSearchResult = YES;

    }

    }


    20. 對于多次點擊只執行最后一次操作

    http://blog.csdn.net/fengsh998/article/details/11112885

    //取消延遲時間之前的操作

    ??[NSObjectcancelPreviousPerformRequestsWithTarget:self];

    ? ?[selfperformSelector:@selector(searchDelay:)withObject:text afterDelay:kDelayTime];


    21. 對于線程:NSObject、NSThread、NSOperationQueue、GCD區別

    如果想取消已經執行的線程:NSThread、NSopeartionQueue的cancel方法,只能立馬改變這個線程的標志位([NSThread currentThread].isCancel)屬性,并不能立即取消到線程的操作;所以要在線程的操作中加上標志位判斷來強制盡快的結束掉線程

    對于多個線程共享資源的爭奪問題:

    記得加上同步鎖/、atomic原子屬性

    NSThr



    22.友盟統計

    http://dev.umeng.com/analytics/ios/quick-start

    23. sqlite 的觸發器使用

    /*

    當T_EC_ADDR 中的name一列進行update 操作,就會觸發執行)update T_EC_ADDR set IS_NAME_CHANGE = 1 where NAME = new.NAME and new.NAME != old.NAME;?

    一個事件的產生影響了另一個事件執行

    */

    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.?








    總結

    以上是生活随笔為你收集整理的NJ 学习点滴积累的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。