iOS开发小技巧总结1

好久没写博客了,现在总结一下平时开发时遇到的一些问题,以及解决方案。下面以问答方式来记录

1、当使用UITableView 的Plain风格时,cell的数量占不满一屏时,会出现无用的cell分割线,如何去掉呢?

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section  
  2. {  
  3.     return 0.01f;  
  4. }  
  5. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section  
  6. {  
  7.     return [UIView new];  
  8.       
  9.     // If you are not using ARC:  
  10.     // return [[UIView new] autorelease];  
  11. }  

2、如何获取iOS 的idfa和mac地址

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1.                     //for mac  
  2. #include <sys/socket.h>  
  3. #include <sys/sysctl.h>  
  4. #include <net/if.h>  
  5. #include <net/if_dl.h>  
  6.   
  7. //for idfa  
  8. #import <AdSupport/AdSupport.h>  
  9.   
  10. - (NSString * )macString{  
  11.       
  12.     int                 mib[6];  
  13.     size_t              len;  
  14.     char                *buf;  
  15.     unsigned char       *ptr;  
  16.     struct if_msghdr    *ifm;  
  17.     struct sockaddr_dl  *sdl;  
  18.       
  19.     mib[0] = CTL_NET;  
  20.     mib[1] = AF_ROUTE;  
  21.     mib[2] = 0;  
  22.     mib[3] = AF_LINK;  
  23.     mib[4] = NET_RT_IFLIST;  
  24.       
  25.     if ((mib[5] = if_nametoindex("en0")) == 0) {  
  26.         printf("Error: if_nametoindex error\n");  
  27.         return NULL;  
  28.     }  
  29.       
  30.     if (sysctl(mib, 6NULL, &len, NULL0) < 0) {  
  31.         printf("Error: sysctl, take 1\n");  
  32.         return NULL;  
  33.     }  
  34.       
  35.     if ((buf = malloc(len)) == NULL) {  
  36.         printf("Could not allocate memory. error!\n");  
  37.         return NULL;  
  38.     }  
  39.       
  40.     if (sysctl(mib, 6, buf, &len, NULL0) < 0) {  
  41.         printf("Error: sysctl, take 2");  
  42.         free(buf);  
  43.         return NULL;  
  44.     }  
  45.       
  46.     ifm = (struct if_msghdr *)buf;  
  47.     sdl = (struct sockaddr_dl *)(ifm + 1);  
  48.     ptr = (unsigned charchar *)LLADDR(sdl);  
  49.     NSString *macString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",  
  50.                            *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];  
  51.     free(buf);  
  52.       
  53.     return macString;  
  54. }  
  55.   
  56. - (NSString *)idfaString {  
  57.       
  58.     NSBundle *adSupportBundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/AdSupport.framework"];  
  59.     [adSupportBundle load];  
  60.       
  61.     if (adSupportBundle == nil) {  
  62.         return @"";  
  63.     }  
  64.     else{  
  65.           
  66.         Class asIdentifierMClass = NSClassFromString(@"ASIdentifierManager");  
  67.           
  68.         if(asIdentifierMClass == nil){  
  69.             return @"";  
  70.         }  
  71.         else{  
  72.               
  73.             //for no arc  
  74.             //ASIdentifierManager *asIM = [[[asIdentifierMClass alloc] init] autorelease];  
  75.             //for arc  
  76.             ASIdentifierManager *asIM = [[asIdentifierMClass alloc] init];  
  77.               
  78.             if (asIM == nil) {  
  79.                 return @"";  
  80.             }  
  81.             else{  
  82.                   
  83.                 if(asIM.advertisingTrackingEnabled){  
  84.                     return [asIM.advertisingIdentifier UUIDString];  
  85.                 }  
  86.                 else{  
  87.                     return [asIM.advertisingIdentifier UUIDString];  
  88.                 }  
  89.             }  
  90.         }  
  91.     }  
  92. }  
  93.   
  94. - (NSString *)idfvString  
  95. {  
  96.     if([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {  
  97.         return [[UIDevice currentDevice].identifierForVendor UUIDString];  
  98.     }  
  99.       
  100.     return @"";  
  101. }  
  102.                   
不过请注意:iOS7之后,mac地址就获取不到了。参考(转):

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 英文原文:In iOS 7 and later, if you ask for the MAC address of an iOS device, the system returns the value 02:00:00:00:00:00. If you need to identify the device, use the identifierForVendor property of UIDevice instead. (Apps that need an identifier for their own advertising purposes should consider using the advertisingIdentifier property of ASIdentifierManager instead.)  
  2. 翻译:从iOS7及更高版本往后,如果你向ios设备请求获取mac地址,系统将返回一个固定值“02:00:00:00:00:00”,如果你需要识别设备的 唯一性,请使用UIDevice的identifierForVendor属性。(因广告目的而需要识别设备的应用,请考虑使用 ASIdentifierManager的advertisingIdentifier属性作为替代)  

3、是不是为了UITextFiled在TableView中被遮挡而烦恼,试试下面的这段代码把。  让TableViewCell中UITextFiled随点击滚动到可视位置

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //textfile uitableview滚动  
  2.   
  3.   
  4.     UITableViewCell *cell;  
  5.     if (!IS_OS_7_OR_LATER) {  
  6.         // Load resources for iOS 6.1 or earlier  
  7.         cell = (UITableViewCell *) textField.superview.superview;  
  8.           
  9.     } else {  
  10.         // Load resources for iOS 7 or later  
  11.         cell = (UITableViewCell *) textField.superview.superview.superview;  
  12.         // TextField -> UITableVieCellContentView -> (in iOS 7!)ScrollView -> Cell!  
  13.     }  

4、让UITableView的Cell不重用

有时候我们的UITableview的cell是有限的10个8个的,根本没必要重用。重用反而导致很多问题。其中思路就是,给这有限的10个cell不同的标示

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath   
  2. {   
  3.        
  4.     NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]];//以indexPath来唯一确定cell   
  5.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell   
  6.     if (cell == nil) {   
  7.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];   
  8.     }   
  9. }   

5、在iOS 7,如何检测到系统自带ViewController手势返回结束

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated  
  2. {  
  3.         id<UIViewControllerTransitionCoordinator> tc = navigationController.topViewController.transitionCoordinator;  
  4.         [tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {  
  5.             NSLog(@"7: %i", [context isCancelled]);  
  6.     }];  
  7. }  

这个检测需要设置 self.navigationController.delegate = self; 当前viewController要UINavigationBarDelegate实现此协议。

还有一个关键的设置,需要在当前ViewController适当的地方设置self.navigationController.delegate = nil;  否则会导致崩溃。我是这样设置的,

在viewDidAppear设置self.navigationController.delegate = self; viewDidDisAppear时设置self.navigationController.delegate = nil;

保证设置成双成对。

参考:http://stackoverflow.com/questions/20639006/getting-interactivepopgesturerecognizer-dismiss-callback-event


6、如何设置Plain 风格下UITableView的Section的HeaderView不在UITableview上浮动

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. CGFloat dummyViewHeight = 40;  
  2. UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(00self.tableView.bounds.size.width, dummyViewHeight)];  
  3. self.tableView.tableHeaderView = dummyView;  
  4. self.tableView.contentInset = UIEdgeInsetsMake(-dummyViewHeight, 000);  

上面 dummyViewHeight的值根据自己headerView的高度变化。就是你headerView的高度。


7、解决企业证书在7.1系统下,无法安装 证书报错的问题

思路:服务器证书或自签名的证书不行,DropBox的网盘的文件访问是https的。可以解决这个问题可以把plist文件传输到DropBox网盘里,访问即可。

把manifest的plist文件放到Dropbox中,并拷贝出分享链接,如:https://www.dropbox.com/s/sdljgdlsj24343j.plist

至于manifest的ipa包的文件可以放到自己的服务器上。这样访问速度和上传大小都不收限制。这个方法我试验过,非常好用。

据说国内https://portal.qiniu.com/signin 七牛存储也有这样的功能。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直接抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直接抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值