1:兩種方法刪除NSUserDefaults所有記錄
//方法一NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; //方法二- (void)resetDefaults { NSUserDefaults * defs = [NSUserDefaults standardUserDefaults]; NSDictionary * dict = [defs dictionaryRePResentation]; for (id key in dict) { [defs removeObjectForKey:key]; } [defs synchronize];}
2:設(shè)置全局navigation barbuttonitem
#pragma mark 設(shè)置全局navigation barbuttonitem -(void)setNaviBarButtonItemImage:(NSString *)imageName andX:(NSInteger)x andY:(NSInteger)y andW:(NSInteger)w andH:(NSInteger)h andTitle:(NSString *)title andSel:(SEL)sel andLOrR:(NSString *)lOr andTitleColor:(UIColor *)color{ UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame =CGRectMake(x,y,w,h); [btn setTitle:title forState:UIControlStateNormal]; if (imageName.length==0 && title.length==0) { } else if (imageName.length==0 && title.length!=0) { [btn setBackgroundColor:[UIColor clearColor]]; [btn setTitleColor:color forState:UIControlStateNormal]; }else if(imageName.length!=0 && title.length==0){ UIImage *image = [UIImage imageNamed:imageName]; [btn setImage:image forState:UIControlStateNormal]; }else if(imageName.length!=0 && title.length!=0){ UIImage *image = [UIImage imageNamed:imageName]; [btn setBackgroundImage:image forState:UIControlStateNormal]; [btn setBackgroundColor:[UIColor clearColor]]; [btn setTitleColor:color forState:UIControlStateNormal]; } [btn addTarget: self action:sel forControlEvents: UIControlEventTouchUpInside]; UIBarButtonItem *bBtn = [[UIBarButtonItem alloc]initWithCustomView:btn]; if ([lOr isEqualToString:@"left"]) { [self.navigationItem setLeftBarButtonItem:bBtn]; }else{ [self.navigationItem setRightBarButtonItem:bBtn]; } }
3:UITableView設(shè)置Section間距
在使用IOS的UITableView時(shí),時(shí)常會(huì)用到它的UITableViewStyleGrouped分組多section屬性。而默認(rèn)的情況下使用該屬性后section之間的間距會(huì)比較大,看著很不舒服。那么可以通過(guò)以下的代理方法配置UITableView各個(gè)section的間距。原理其實(shí)很簡(jiǎn)單,顯示效果的各個(gè)section間距其實(shí)是section頭部和底部的組合。配置他們的間距就是配置各個(gè)section的頭部和底部//section頭部間距 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 1;//section頭部高度 } //section頭部視圖 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)]; view.backgroundColor = [UIColor clearColor]; return [view autorelease]; } //section底部間距 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 1; } //section底部視圖 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)]; view.backgroundColor = [UIColor clearColor]; return [view autorelease]; }
4:解決OBJC_CLASS_$_MBProgressHUD無(wú)法引用的問(wèn)題
雖然用POD把相關(guān)文件已經(jīng)更新下來(lái),但它卻沒(méi)有引入到工程中,要手動(dòng)對(duì)它進(jìn)行引用(或者直接放棄pod管理此插件,直接引入工程項(xiàng)目源代碼中)Undefined symbols for architecture i386: "_OBJC_CLASS_$_MBProgressHUD", referenced from: objc-class-ref in ViewController.old: symbol(s) not found for architecture i386clang: error: linker command failed with exit code 1 (use -v to see invocation)這里的錯(cuò)誤是因?yàn)槟愕脑赽uilding phases中沒(méi)有引用相關(guān)的頭文件,因此,只需要在building phase中添加對(duì)應(yīng)的.m文件就可以了。
5:iOS7 下使用SVPullToRefresh 下拉刷新導(dǎo)航欄位置錯(cuò)誤
iOS7 下使用SVPullToRefresh 下拉刷新導(dǎo)航欄位置錯(cuò)誤;下拉刷新之后,tableview的第一列會(huì)跑到導(dǎo)航欄的下面;修正:添加如下代碼/** * 下拉刷新 增加一個(gè); */ //修復(fù)下拉刷新位置錯(cuò)誤 代碼開(kāi)始if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) { self.automaticallyAdjustsScrollViewInsets = NO; UIEdgeInsets insets = self.tableView.contentInset; insets.top = self.navigationController.navigationBar.bounds.size.height + [UIapplication sharedApplication].statusBarFrame.size.height; self.tableView.contentInset = insets; self.tableView.scrollIndicatorInsets = insets;}//修復(fù)下拉刷新位置錯(cuò)誤 代碼結(jié)束__block RootViewController *bSelf = self; [self.tableView addPullToRefreshWithActionHandler:^{ [bSelf addRows];}]; /** * 拉到最后 加載更多,增加一個(gè); */[self.tableView addInfiniteScrollingWithActionHandler:^{ [bSelf addMoreRow];}];
6:當(dāng)改動(dòng)布局要更新效果時(shí)
CGRect headFrame=self.headerView.frame;headFrame.size.height=200;self.headerView.frame = headFrame;[self.headerView setNeedsLayout];[self.headerView layoutIfNeeded];
7:給UITextField增加一個(gè)右邊內(nèi)的圖片按鍵(rightView)
UIButton *addCommentBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40,inputTextViewHeight)];[addCommentBtn setImage:[UIImage imageNamed:@"textViewEditNormal"] forState:UIControlStateNormal];[addCommentBtn addTarget:self action:@selector(addCommentAction) forControlEvents:UIControlEventTouchUpInside];_inputTextView.rightView=addCommentBtn;_inputTextView.rightViewMode=UITextFieldViewModeAlways;
8:NSLog 輸出格式集合
• %@ 對(duì)象• %d, %i 整數(shù)• %u 無(wú)符整形• %f 浮點(diǎn)/雙字• %x, %X 二進(jìn)制整數(shù)• %o 八進(jìn)制整數(shù)• %zu size_t• %p 指針• %e 浮點(diǎn)/雙字 (科學(xué)計(jì)算)• %g 浮點(diǎn)/雙字• %s C 字符串• %.*s Pascal字符串• %c 字符• %C unichar• %lld 64位長(zhǎng)整數(shù)(long long)• %llu 無(wú)符64位長(zhǎng)整數(shù)%Lf 64位雙字
9:設(shè)置UIImage的渲染模式:UIImage.renderingMode
設(shè)置UIImage的渲染模式:UIImage.renderingMode著色(Tint Color)是iOS7界面中的一個(gè).設(shè)置UIImage的渲染模式:UIImage.renderingMode重大改變,你可以設(shè)置一個(gè)UIImage在渲染時(shí)是否使用當(dāng)前視圖的Tint Color。UIImage新增了一個(gè)只讀屬性:renderingMode,對(duì)應(yīng)的還有一個(gè)新增方法:imageWithRenderingMode:,它使用UIImageRenderingMode枚舉值來(lái)設(shè)置圖片的renderingMode屬性。該枚舉中包含下列值: 1 UIImageRenderingModeAutomatic // 根據(jù)圖片的使用環(huán)境和所處的繪圖上下文自動(dòng)調(diào)整渲染模式。 2 UIImageRenderingModeAlwaysOriginal // 始終繪制圖片原始狀態(tài),不使用Tint Color。 3 UIImageRenderingModeAlwaysTemplate // 始終根據(jù)Tint Color繪制圖片,忽略圖片的顏色信息。 renderingMode屬性的默認(rèn)值是UIImageRenderingModeAutomatic,即UIImage是否使用Tint Color取決于它顯示的位置。UIImage *img = [UIImage imageNamed:@ "myimage" ]; img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 使用場(chǎng)景(Toolbar中增加item,item使用背景圖,會(huì)出現(xiàn)色調(diào)為藍(lán)色,如果要為圖片原來(lái)的色調(diào),則要修改圖片的渲染,因?yàn)槟壳笆卿秩境晌淖值纳{(diào)):@property (weak, nonatomic) IBOutlet UIBarButtonItem *mycollectionItem;UIImage *collectionItemImage=[UIImage imageNamed:@"bottomCollectionNormal"];collectionItemImage=[collectionItemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];self.mycollectionItem.image=collectionItemImage;
10:navigationController當(dāng)前頁(yè)隱藏后跳轉(zhuǎn)回去頁(yè)同樣被隱藏
當(dāng)前頁(yè)隱藏代碼:[self.navigationController setNavigationBarHidden:YES];跳轉(zhuǎn)時(shí):[self.navigationController setNavigationBarHidden:NO];[self.navigationController popViewControllerAnimated:YES];
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注