Tag: 循环

如何检查json对象的数组中的多个键相同的值?

我正在使用Swift3在日历上工作。 我知道可以为不同的键设置相同的值。 我有这个名为Dictionary of JSON objects的NSArray : if parsedData["status"] as! Int == 200 { if let Streams = parsedData["data"] as! [AnyObject]? { for Stream in Streams { print(Stream) } Stream result: { "-" = 4; 1 = X; 10 = H; 11 = X; 12 = X; 13 = X; 14 = X; 15 = […]

迭代结构的静态属性

有一个简单的方法来遍历一个结构的所有属性? 我熟悉的非静态属性的方法是使用Mirror ,但是当结构只包含静态属性时,这将返回一个空数组。 这是我想要实现的一个例子: struct Tree { static let bark = "Bark" static let roots = "Roots" } let treeParts = [String]() // insert code here to make treeParts = ["Bark", "Roots"]

Swift延迟循环

我有这个延迟function: func delay(delay:Double, closure:()->()) { dispatch_after( dispatch_time( DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)) ), dispatch_get_main_queue(), closure) } 从这里开始: dispatch_after – GCD在swift中? 此代码: func start(){ for index in 1…3 { delay(3.0){ println(index) } } } 3秒后,它给: 3 3 3 我的目标: 3秒后:1 6秒后:2 9秒后:3 我该怎么做到这一点? 谢谢,

在objective-c中循环有效

我使用Parse作为我的后端服务,但是对于这个例子,我创build了两个模拟我的后端架构的样本数组( songs和ratings )。 songs由歌曲数据组成,将填充我的应用程序的表。 ratings包括当前用户对歌曲的评分。 最终,我需要循环songs和ratings ,将userRatingembedded各自的songs字典中。 我已经在下面包含了我的循环代码。 这可以做得更有效率吗? 如果ratings对象太多,我担心这会花费太长时间。 NSMutableArray *songs = [@[ @{ @"objectId" : @"111", @"title" : @"Song Title" }, @{ @"objectId" : @"222", @"title" : @"Song Title" } ] mutableCopy]; NSMutableArray *ratings = [@[ @{ @"objectId" : @"999", @"parentObjectId" : @"111", @"userRating" : @4 } ] mutableCopy]; for (NSInteger a = […]

从数组中填充一个UITableView

我需要帮助下面的代码我使用hppleparsinghtml。 我需要帮助利用这些数据。 -(void) whatever{ NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding]; TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData]; NSArray *titles = [xpathParser search:@"//h3"]; // get the page title – this is xpath notation TFHppleElement *title = [titles objectAtIndex:0]; NSString *myTitles = [title content]; NSArray *articles = [xpathParser search:@"//h4"]; // get the page article – this […]

目标-c中的循环和asynchronous连接

我有一个表名称的数组,并希望循环他们,并采取他们的名字和附加一个URL来创build一个连接到一个Web服务来下载JSON数据。 循环似乎首先工作,arrays中的三个表名中的每一个都被用来创build到Web服务的连接,并且数据被下载,但是当循环结束时(从3到0)循环出现再次启动并无限循环数组中的最后两个表。 日志输出(注意演讲者和参展者反复重复): 2013-12-16 10:38:08.755 WebServiceTest[501:60b] loopCount = 3 2013-12-16 10:38:08.758 WebServiceTest[501:60b] table name = workshop 2013-12-16 10:38:08.817 WebServiceTest[501:60b] LoopCount is: 2 2013-12-16 10:38:08.821 WebServiceTest[501:60b] loopCount = 2 2013-12-16 10:38:08.822 WebServiceTest[501:60b] table name = exhibitor 2013-12-16 10:38:08.827 WebServiceTest[501:60b] LoopCount is: 1 2013-12-16 10:38:08.830 WebServiceTest[501:60b] loopCount = 1 2013-12-16 10:38:08.831 WebServiceTest[501:60b] table name = speaker 2013-12-16 […]

IOS:具有无限分页视图的UIScrollView

我有一个滚动视图的代码showe 3图像: const CGFloat kScrollObjHeight = 150.0; const CGFloat kScrollObjWidth = 320.0; const NSUInteger kNumImages = 3; – (void)layoutScrollImages { UIImageView *view = nil; NSArray *subviews = [scrollView1 subviews]; // reposition all image subviews in a horizontal serial fashion CGFloat curXLoc = 0; for (view in subviews) { if ([view isKindOfClass:[UIImageView class]] && view.tag > […]

UITableView显示循环的最后一个值

我想在tableview中显示这个循环的所有值。 代码是计算贷款摊销表。 我试图保存数组中的循环数据,但它总是给我最后的值。 我真的被困在这个。 那么请问我该怎么做? 这是我的代码: import UIKit class tableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet var tableView: UITableView! var arr = [Int]() var cell:tableCell! var TPayment: float_t! // calls value of 59600 from main controller var years1: float_t! // number of months = 180 ( 15 years) var monthlyPayment: float_t! // 471 var interest: float_t! […]

使用循环向多个UIImageView添加属性

我有8个UImageView ,我正在添加animation。 我知道我可以做animation八次,但我可以使用一个循环,也许插值 – 它? 这是我的animation代码: override func viewDidLoad() { super.viewDidLoad() self.dieImage0.animationImages = [ UIImage(named: "dicey-die1")!, UIImage(named: "dicey-die2")!, UIImage(named: "dicey-die3")!, UIImage(named: "dicey-die4")!, UIImage(named: "dicey-die5")!, UIImage(named: "dicey-die6")!, UIImage(named: "dicey-die1")!, UIImage(named: "dicey-die2")!, UIImage(named: "dicey-die3")!, UIImage(named: "dicey-die4")!, UIImage(named: "dicey-die5")!, UIImage(named: "dicey-die6")!, UIImage(named: "dicey-die1")!, UIImage(named: "dicey-die2")!, UIImage(named: "dicey-die3")!, UIImage(named: "dicey-die4")!, UIImage(named: "dicey-die5")!, UIImage(named: "dicey-die6")!, UIImage(named: "dicey-die1")!, UIImage(named: "dicey-die2")!, UIImage(named: […]

如何给循环添加一个延迟?

我试图使用此代码添加图像视图到UIView: for (int i = 0; i <numberOfImages; i++) { UIImageView *image = [UIImageView alloc]initWithFrame:CGRectMake(40, 40, 40, 40)]; image.image = [images objectAtIndex:i]; [self.view addSubview:image]; } 这工作,但问题是我想有一个5秒的延迟之前,它添加每个图像,而是它们都在同一时间添加。 有人可以帮我吗? 谢谢。 例: 5 seconds = one image on screen 10 seconds = two images on screen 15 seconds = three images on screen