我一直在尝试将一系列标签添加到我的收藏视图单元格中,但它们没有显示出来。
import UIKit
class HomeMenuViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var codes = ["NBA","NFL","Girls","Rappers","Celebrities","NFL Teams","Travel","Models","Foodies","Musician","Companies/Brands","Youtube/Viral Stars","Fitness","Snapchat Art","Fashion/Makeup", "MLB Teams"]
var images = [UIImage(named: "title617792344"),UIImage(named: "title236271662"),UIImage(named: "title713937166"),UIImage(named: "title718520594"),UIImage(named: "title205571580"),UIImage(named: "title193064553"),UIImage(named: "title800939906"),UIImage(named: "title987804505"),UIImage(named: "title528311821"),UIImage(named: "title673858816"),UIImage(named: "title543192229"),UIImage(named: "title351533554"),UIImage(named: "title311505831"),UIImage(named: "title579492173-1"), UIImage(named: "title743923696"),UIImage(named: "title544380635")]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 16
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCell(withReuseIdentifier: "uicvcell", for: indexPath) as! HomeMenuCollectionViewCell
var image = cell.viewWithTag(1) as! UIImageView
image.image = images[indexPath.row]
var code = cell.viewWithTag(2) as! UILabel
code.text = codes [indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if(indexPath.row == Int("0")){
performSegue(withIdentifier: "0", sender: nil)
}
else if(indexPath.row == Int("1")){
performSegue(withIdentifier: "1", sender: nil)
}
else if(indexPath.row == Int("2")){
performSegue(withIdentifier: "2", sender: nil)
}
else if(indexPath.row == Int("3")){
performSegue(withIdentifier: "3", sender: nil)
}
else if(indexPath.row == Int("4")){
performSegue(withIdentifier: "4", sender: nil)
}
else if(indexPath.row == Int("5")){
performSegue(withIdentifier: "5", sender: nil)
}
else if(indexPath.row == Int("6")){
performSegue(withIdentifier: "6", sender: nil)
}
else if(indexPath.row == Int("7")){
performSegue(withIdentifier: "7", sender: nil)
}
else if(indexPath.row == Int("8")){
performSegue(withIdentifier: "8", sender: nil)
}
else if(indexPath.row == Int("9")){
performSegue(withIdentifier: "9", sender: nil)
}
else if(indexPath.row == Int("10")){
performSegue(withIdentifier: "10", sender: nil)
}
else if(indexPath.row == Int("11")){
performSegue(withIdentifier: "11", sender: nil)
}
else if(indexPath.row == Int("12")){
performSegue(withIdentifier: "12", sender: nil)
}
else if(indexPath.row == Int("13")){
performSegue(withIdentifier: "13", sender: nil)
}
else if(indexPath.row == Int("14")){
performSegue(withIdentifier: "14", sender: nil)
}
else if(indexPath.row == Int("15")){
performSegue(withIdentifier: "15", sender: nil)
}
else if(indexPath.row == Int("16")){
performSegue(withIdentifier: "16", sender: nil) }
else if(indexPath.row == Int("17")){
performSegue(withIdentifier: "17", sender: nil)
}
else if(indexPath.row == Int("18")){
performSegue(withIdentifier: "18", sender: nil)
}
}
}
这是我的另一个文件,其中包含IBOutlets
。
导入UIKit
class HomeMenuCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var codes: UILabel!
@IBOutlet weak var image: UIImageView!
}
我能够在UICollection视图控制器中执行此操作,但现在我在视图控制器中添加它不起作用。
答案 0 :(得分:0)
DECLARE @tbl AS TABLE([rn] INT IDENTITY(1, 1), [id] INT);
INSERT INTO @tbl([id]) VALUES(5), (64), (2), (8), (7), (1);
SELECT t1.*
FROM [your_table_name] t1
JOIN @tbl t2
ON t1.[id] = t2.[id]
ORDER BY t2.[rn];
并将其与主故事板中的收藏夹视图和
连接在@IBOutlet weak var yourCollectionView:UICollectionView!
方法中添加以下行
ViewDidLoad
答案 1 :(得分:0)
<c:url value="/students/add" var="addStudentAction"></c:url>
<form action="${addStudentAction}" method="get">
<input type="hidden" name="studentId">
<input type="text" name="studentName"></input>
<input type="submit" name="submit" value="Add Student" />
</form>
为什么你需要设置标签并使代码复杂化,但是这将显示标签,你将获得所需的输出