標籤: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開發--經常會用到的方法和常識