Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm trying to repeatedly display images, but I'm getting an out of range error.
Here's my code:
#IBOutlet weak var im: UIImageView!
var images = ["page003.png","page004.png","page005.png","page006.png"]
var indice = 0
#IBAction func n(sender: AnyObject) {
indice++
if indice == images.count
{
indice == 0
}
im.image = UIImage(named: (images[indice]))
}
Replace indice == 0 with indice = 0.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
Improve this question
Hello I wrote this little piece of code, but I have the impression that it is not optimal, indeed as the field variable is in get only : I can not directly change it .... but I am junior : so I would be delighted if someone has a better idea :) thank you .
let keyword = ["potatoes","garlic"]
var field: String {
var element = ""
keyword.forEach {
element += "&field=" + $0
}
return element
}
a shorter code coming from professionalswift developper :)
this would be better
let keyword = ["potatoes","garlic"]
var field: String {
return keyword.map { "&field=\($0)"}.joined()
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This is a really simple program : Calculate Cat years
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var txtOldOfCat: UITextField!
#IBOutlet weak var lblOldOfCat: UILabel!
#IBOutlet weak var imgCat: UIImageView!
#IBAction func btnSubmit(_ sender: Any) {
print(txtOldOfCat.text!)
let catAge = Int(txtOldOfCat.text!)! * 7
print(catAge)
lblOldOfCat.text = String(catAge)
}
}
In the log console, if enter 3 to submit I can read that :
3
21
(11db)
The program breakpoint in Thread 1: breakpoint 1.1 in this line :
{ ...
lblOldOfCat.text = String(catAge)
}
I double check and the link is good betweem my main storyboard and ViewController class.
I really not understand is really easy...
Thank you
If your click on line number it's add a "blue flag' in the margin. This blue flag is a breakpoint in XCode so this is why my program stop at this line. You just need to re-click on the line in blue to delete this break point.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Just started coding and i am running in to the following problem:
I have set up the following struct:
struct Question {
var Question: String!
var Answers: [String]!
var Answer : Int!
var Image : UIImage!
}
Connected the UIImageView as: #IBOutlet var Qimage: UIImageView!
I tried to fill the struct, and all the data is displayed correctly except the image? Example:
Questions = [Question(Question: "test?", Answers: ["1","2","3","4"], Answer: 2, Image: UIImage(contentsOfFile: "test"))
At last i am trying to fill the struct with a function and used:
Qimage.image = Questions[Qnumber].Image
Thanks in advance for the help!
Use: UIImage(named: "Test").. instead of UIImage(contentsOfFile: "Test")
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am in an iOS course and came across this error while making my app:
import Foundation
import UIKit
class RootsCateogry1: ViewController {
#IBOutlet weak var roots1Label: UILabel!
var rootsWeek1 = ["acro", "micro"]
var rootsWeek1Meaning = ["Air", "Small"]
var roots1Show = []
var temp = rootsWeek1.count // error here
var p = 0
var i = 0
while(i<temp){ // error here
roots1Show.append(rootsWeek1temp)
temp++
}
// ...
}
Screenshot
temp is a computed property, not a compile-time constant. You either need to override its getter or place it in your init or viewDidLoad:
var temp: Int {
return rootsWeek1.count
}
or:
override func viewDidLoad() {
super.viewDidLoad()
var temp = rootsWeek1.count
}
Your while loop must go in a function, it cannot exist at the class level. Consider moving that to your viewDidLoad as well. You are also not declaring a variable named rootsWeek1temp before adding it to roots1Show, so the compiler won't know what to append to the array if the object does not exist.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Array1 : { A , B , C }
Array2 : { 1 , 2 , 3 }
I need to combine of this array list like:
Combine array :
{
A(1),
B(2),
C(3)
}
How can I implement this?
you can use NSDictionary
NSDictionary *dict = [NSDictionary dictionaryWithObjects:array1
forKeys:array2];
NSString *value = dict[#"1"]; //value = #"A";