仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2466|回复: 20
打印 上一主题 下一主题

[学习教程] IOS教程之iOS开辟小技能总结1仓酷云

[复制链接]
萌萌妈妈 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:30:22 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Model的改变最好通过Notification来传播之前吃过这样的亏最好不要用delegate模式)UIViewController很久没写博客了,如今总结一下平常开辟时碰到的一些成绩,和办理计划。上面以问答体例来纪录
1、当利用UITableView的Plain作风时,cell的数目占不满一屏时,会呈现无用的cell支解线,怎样往失落呢?


  • -(CGFloat)tableView:(UITableView*)tableViewheightForFooterInSection:(NSInteger)section
  • {
  • return0.01f;
  • }
  • -(UIView*)tableView:(UITableView*)tableViewviewForFooterInSection:(NSInteger)section
  • {
  • return[UIViewnew];

  • //IfyouarenotusingARC:
  • //return[[UIViewnew]autorelease];
  • }
2、怎样猎取iOS的idfa和mac地点


  • //formac
  • #include<sys/socket.h>
  • #include<sys/sysctl.h>
  • #include<net/if.h>
  • #include<net/if_dl.h>

  • //foridfa
  • #import<AdSupport/AdSupport.h>

  • -(NSString*)macString{

  • intmib[6];
  • size_tlen;
  • char*buf;
  • unsignedchar*ptr;
  • structif_msghdr*ifm;
  • structsockaddr_dl*sdl;

  • mib[0]=CTL_NET;
  • mib[1]=AF_ROUTE;
  • mib[2]=0;
  • mib[3]=AF_LINK;
  • mib[4]=NET_RT_IFLIST;

  • if((mib[5]=if_nametoindex("en0"))==0){
  • printf("Error:if_nametoindexerrorn");
  • returnNULL;
  • }

  • if(sysctl(mib,6,NULL,&len,NULL,0)<0){
  • printf("Error:sysctl,take1n");
  • returnNULL;
  • }

  • if((buf=malloc(len))==NULL){
  • printf("Couldnotallocatememory.error!n");
  • returnNULL;
  • }

  • if(sysctl(mib,6,buf,&len,NULL,0)<0){
  • printf("Error:sysctl,take2");
  • free(buf);
  • returnNULL;
  • }

  • ifm=(structif_msghdr*)buf;
  • sdl=(structsockaddr_dl*)(ifm+1);
  • ptr=(unsignedcharchar*)LLADDR(sdl);
  • NSString*macString=[NSStringstringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
  • *ptr,*(ptr+1),*(ptr+2),*(ptr+3),*(ptr+4),*(ptr+5)];
  • free(buf);

  • returnmacString;
  • }

  • -(NSString*)idfaString{

  • NSBundle*adSupportBundle=[NSBundlebundleWithPath:@"/System/Library/Frameworks/AdSupport.framework"];
  • [adSupportBundleload];

  • if(adSupportBundle==nil){
  • return@"";
  • }
  • else{

  • ClassasIdentifierMClass=NSClassFromString(@"ASIdentifierManager");

  • if(asIdentifierMClass==nil){
  • return@"";
  • }
  • else{

  • //fornoarc
  • //ASIdentifierManager*asIM=[[[asIdentifierMClassalloc]init]autorelease];
  • //forarc
  • ASIdentifierManager*asIM=[[asIdentifierMClassalloc]init];

  • if(asIM==nil){
  • return@"";
  • }
  • else{

  • if(asIM.advertisingTrackingEnabled){
  • return[asIM.advertisingIdentifierUUIDString];
  • }
  • else{
  • return[asIM.advertisingIdentifierUUIDString];
  • }
  • }
  • }
  • }
  • }

  • -(NSString*)idfvString
  • {
  • if([[UIDevicecurrentDevice]respondsToSelector:@selector(identifierForVendor)]){
  • return[[UIDevicecurrentDevice].identifierForVendorUUIDString];
  • }

  • return@"";
  • }

不外请注重:iOS7以后,mac地点就猎取不到了。参考(转):

  • 英文原文:IniOS7andlater,ifyouaskfortheMACaddressofaniOSdevice,thesystemreturnsthevalue02:00:00:00:00:00.Ifyouneedtoidentifythedevice,usetheidentifierForVendorpropertyofUIDeviceinstead.(AppsthatneedanidentifierfortheirownadvertisingpurposesshouldconsiderusingtheadvertisingIdentifierpropertyofASIdentifierManagerinstead.)
  • 翻译:从iOS7及更高版本今后,假如你向ios设备哀求猎取mac地点,体系将前往一个流动值“02:00:00:00:00:00”,假如你必要辨认设备的独一性,请利用UIDevice的identifierForVendor属性。(因告白目标而必要辨认设备的使用,请思索利用ASIdentifierManager的advertisingIdentifier属性作为替换)
3、是否是为了UITextFiled在TableView中被遮挡而懊恼,尝尝上面的这段代码把。让TableViewCell中UITextFiled随点击转动到可视地位


  • //textfileuitableview转动


  • UITableViewCell*cell;
  • if(!IS_OS_7_OR_LATER){
  • //LoadresourcesforiOS6.1orearlier
  • cell=(UITableViewCell*)textField.superview.superview;

  • }else{
  • //LoadresourcesforiOS7orlater
  • cell=(UITableViewCell*)textField.superview.superview.superview;
  • //TextField->UITableVieCellContentView->(iniOS7!)ScrollView->Cell!
  • }
4、让UITableView的Cell不重用

偶然候我们的UITableview的cell是无限的10个8个的,基本没需要重用。重用反而招致良多成绩。个中思绪就是,给这无限的10个cell分歧的标示

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

  • NSString*CellIdentifier=[NSStringstringWithFormat:@"Cell%d%d",[indexPathsection],[indexPathrow]];//以indexPath来独一断定cell
  • UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:CellIdentifier];//出列可重用的cell
  • if(cell==nil){
  • cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];
  • }
  • }
5、在iOS7,怎样检测到体系自带ViewController手势前往停止


  • -(void)navigationController:(UINavigationController*)navigationControllerwillShowViewController:(UIViewController*)viewControlleranimated:(BOOL)animated
  • {
  • id<UIViewControllerTransitionCoordinator>tc=navigationController.topViewController.transitionCoordinator;
  • [tcnotifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext>context){
  • NSLog(@"7:%i",[contextisCancelled]);
  • }];
  • }
这个检测必要设置self.navigationController.delegate=self;以后viewController要UINavigationBarDelegate完成此协定。
另有一个关头的设置,必要在以后ViewController得当的中央设置self.navigationController.delegate=nil;不然会招致溃散。我是如许设置的,
在viewDidAppear设置self.navigationController.delegate=self;viewWillDisappear时设置self.navigationController.delegate=nil;
包管设置成双成对。
参考:http://stackoverflow.com/questions/20639006/getting-interactivepopgesturerecognizer-dismiss-callback-event

只能IB识别IB也没那么高深XIB文件解开之后就是一堆代码之前面过一家小公司看我当时写的程序里面用到了IB一脸不屑
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-16 18:09

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表