IOS開發--經常會用到的方法和常識

來源:互聯網
上載者:User

標籤:ios開發   objective-c   nsstring   遍曆   

改變狀態列顏色;

-(UIStatusBarStyle)preferredStatusBarStyle

{

    return UIStatusBarStyleLightContent;

}

是否顯示狀態列

- (BOOL)prefersStatusBarHidden

{

    return YES;

}


// 讓數組中的所有對象都執行removeFromSuperview方法

    [self.answerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];


//xib檔案初始化之後調用這個方法

-(void) awakeFromNib{}

//計算text字串的size

- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize

{

    NSDictionary *attrs = @{NSFontAttributeName : font};

    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;

}

OC遍曆字串

1) 通過尋找的方式來(這方式適合所有格式的子符串,推薦使用)

   NSString *newStr [email protected]"abdcdddccdd00大家好哦";

   NSString *temp = nil;

   for(int i =0; i < [newStr length]; i++)  

   {   

       temp = [newStr substringWithRange:NSMakeRange(i, 1)];

       NSLog(@"第%d個字是:%@",i,temp);

   }  

   

(2) 通過遍曆字元的方式遍曆字串(只適合不包含中文的字串)

        

   NSString *newStr = @"abdcdddccdd00";


   for(int i =0; i < [newStr length]; i++)  

   {   

      NSLog(@"第%d個字元是:%@",i, [newStr characterAtIndex:i]);

   }  


螢幕寬度:CGFloat screenW=[UIScreen mainScreen].bounds.size,width;
重新整理表格;[self.tableView reloadData];

重寫父類的description方法:

description方法:當使用%@列印一個對象的時候,會調用這個方法 

 在student.m檔案中,重寫description方法: 

-(NSString *)description {     NSString *str = [NSString stringWithFormat:@"age is %i and no %i",_age,_no];     return str; } 

在main.m的main函數中測試: 

Student *student = [[Student alloc]initWithAge:15 AndNo:2]; NSLog(@"%@",student); [student release];

輸出: 

2013-07-19 00:02:19.410 構造方法[2446:303] age is 15 and no is 2 


顯示Mac隱藏檔案的命令:defaults write com.apple.finder AppleShowAllFiles -bool true隱藏Mac隱藏檔案的命令:defaults write com.apple.finder AppleShowAllFiles -bool false

ARC與非ARC在一個項目中同時使用:

1,選擇項目中的Targets,選中你所要操作的Target,
2,選Build Phases,在其中Complie Sources中選擇需要ARC的檔案雙擊,並在輸入框中輸入:-fobjc-arc,如果不要ARC則輸入:-fno-objc-arc

當對象被存入集合中的時候,預設會儲存它的強指標當把你個對象從集合中刪除的時候,會釋放掉這個對象的強指標。


IOS開發--經常會用到的方法和常識

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.