我非常新的Xcode和刷卡,非常感謝任何幫助。我爲屏幕上半部分的單詞列表創建了一個隨機生成器(頂部標籤,這包含在代碼中)。我如何調整這段代碼,以便我可以在屏幕的下半部分使用不同的單詞列表(底部標籤不是指向任何代碼)?但是對於相同的點擊按鈕來隨機化這兩個單詞列表? The layout of the screen如何在同一視圖控制器上的2個不同視圖上實現隨機生成器?
進口的UIKit
類的ViewController:UIViewController的{// 把標籤和按鈕
@IBOutlet var InspirationalThought: UILabel!
@IBOutlet var Click: UIButton!
//what the label is going to show
var quotes = ["Geometrics", "Vectors", "Celebration", "Triangle", "Landscapes", "Seasons", "Snow", "Rain", "Sunrays", "Stencils", "Paint", "Graphics", "Graffiti", "Sports","Fashion",
"Ancient Greek", "Philosophers", "Fairy Tales", "Fantasy", "Clouds", "Mystery", "Time Clocks", "Canvas", "Tie-dye", "Glitter", "Dessert", "Desert", "Energy", "Astrology", "Solar Systems", "Sea", "Beach", "Sphere", "Roots", "Lights", "Darks", "Fire", "Air",
"Aperture", "Long exposure", "Portraits", "World", "Travel", "Architecture", "Freedom", "Old", "New", "Urban", "Lenses", "Fisheye", "Chords", "Music Notes", "Spices", "Herbs", "Natural", "Marbles", "Wood", "Trees", "Forests", "Interior",
"Mammals", "Reptiles", "Ocean", "Birds", "Photography", "Exposure", "Opaque", "Translucent", "Freestyle", "Spots", "Stripes", "Zig Zag", "Spiral", "Glass", "Feathers", "Calm", "Bulb", "Heat", "Cold", "Stitches", "Views", "Birds", "Sunset", "Earth"]
var whichQuotestoChoose = 0
// what the button is going to show
var ButtonText = ["Inspiration", "Tell me more", "more inspirational"]
var whichButtonTexttoChoose = 0
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func ClickButtonClicked(sender: UIButton) {
chooseAQuote()
chooseTextonButton()
}
func chooseAQuote(){
showTheQuote()
whichQuotestoChoose = Int(arc4random_uniform (84))
}
func showTheQuote(){
InspirationalThought.text = "\(quotes[whichQuotestoChoose])"
}
func chooseTextonButton(){
Click.setTitle("\(ButtonText[whichButtonTexttoChoose])", forState: UIControlState.Normal)
}
}
我有點困惑,因爲只有一個代碼標籤,但你有兩個佈局。 – penatheboss
對不起,底部標籤尚未連接到代碼。 –
一旦你這樣做,你能[編輯你的問題](http://stackoverflow.com/posts/37100997/edit)嗎? – penatheboss