好久没写博客了,现在总结一下平时开发时遇到的一些问题,以及解决方案。下面以问答方式来记录
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01f; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; // If you are not using ARC: // return [[UIView new] autorelease]; }
//for mac #include <sys/socket.h> #include <sys/sysctl.h> #include <net/if.h> #include <net/if_dl.h> //for idfa #import <AdSupport/AdSupport.h> - (NSString * )macString{ int mib[6]; size_t len; char *buf; unsigned char *ptr; struct if_msghdr *ifm; struct sockaddr_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_nametoindex error\n"); return NULL; } if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { printf("Error: sysctl, take 1\n"); return NULL; } if ((buf = malloc(len)) == NULL) { printf("Could not allocate memory. error!\n"); return NULL; } if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { printf("Error: sysctl, take 2"); free(buf); return NULL; } ifm = (struct if_msghdr *)buf; sdl = (struct sockaddr_dl *)(ifm + 1); ptr = (unsigned char *)LLADDR(sdl); NSString *macString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)]; free(buf); return macString; } - (NSString *)idfaString { NSBundle *adSupportBundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/AdSupport.framework"]; [adSupportBundle load]; if (adSupportBundle == nil) { return @""; } else{ Class asIdentifierMClass = NSClassFromString(@"ASIdentifierManager"); if(asIdentifierMClass == nil){ return @""; } else{ //for no arc //ASIdentifierManager *asIM = [[[asIdentifierMClass alloc] init] autorelease]; //for arc ASIdentifierManager *asIM = [[asIdentifierMClass alloc] init]; if (asIM == nil) { return @""; } else{ if(asIM.advertisingTrackingEnabled){ return [asIM.advertisingIdentifier UUIDString]; } else{ return [asIM.advertisingIdentifier UUIDString]; } } } } } - (NSString *)idfvString { if([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) { return [[UIDevice currentDevice].identifierForVendor UUIDString]; } return @""; }不过请注意:iOS7之后,mac地址就获取不到了。参考(转):
英文原文: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.) 翻译:从iOS7及更高版本往后,如果你向ios设备请求获取mac地址,系统将返回一个固定值“02:00:00:00:00:00”,如果你需要识别设备的 唯一性,请使用UIDevice的identifierForVendor属性。(因广告目的而需要识别设备的应用,请考虑使用 ASIdentifierManager的advertisingIdentifier属性作为替代)
//textfile uitableview滚动 UITableViewCell *cell; if (!IS_OS_7_OR_LATER) { // Load resources for iOS 6.1 or earlier cell = (UITableViewCell *) textField.superview.superview; } else { // Load resources for iOS 7 or later cell = (UITableViewCell *) textField.superview.superview.superview; // TextField -> UITableVieCellContentView -> (in iOS 7!)ScrollView -> Cell! }
有时候我们的UITableview的cell是有限的10个8个的,根本没必要重用。重用反而导致很多问题。其中思路就是,给这有限的10个cell不同的标示
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]];//以indexPath来唯一确定cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } }
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { id<UIViewControllerTransitionCoordinator> tc = navigationController.topViewController.transitionCoordinator; [tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) { NSLog(@"7: %i", [context isCancelled]); }]; }
这个检测需要设置 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
CGFloat dummyViewHeight = 40; UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, dummyViewHeight)]; self.tableView.tableHeaderView = dummyView; self.tableView.contentInset = UIEdgeInsetsMake(-dummyViewHeight, 0, 0, 0);
思路:服务器证书或自签名的证书不行,DropBox的网盘的文件访问是https的。可以解决这个问题可以把plist文件传输到DropBox网盘里,访问即可。
把manifest的plist文件放到Dropbox中,并拷贝出分享链接,如:https://www.dropbox.com/s/sdljgdlsj24343j.plist
把分享到链接前面域名:https://www.dropbox.com 替换成:https://dl.dropboxusercontent.com,就是整整plist地址
至于manifest的ipa包的文件可以放到自己的服务器上。这样访问速度和上传大小都不收限制。这个方法我试验过,非常好用。
据说国内https://portal.qiniu.com/signin 七牛存储也有这样的功能。