Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS Swift UICollectionView,我希望每个单元格都有不同的标记?_Ios_Xcode_Swift_Ios8_Uicollectionview - Fatal编程技术网

IOS Swift UICollectionView,我希望每个单元格都有不同的标记?

IOS Swift UICollectionView,我希望每个单元格都有不同的标记?,ios,xcode,swift,ios8,uicollectionview,Ios,Xcode,Swift,Ios8,Uicollectionview,您知道,在TableView中,您可以设置一个数组,然后将数组的每个元素作为行的文本放置,例如: 我有一个桌面视图 数组:items=[你好,世界,是] 在cellforrowatinexpath函数中,您只需说:cell.text=items[indexPath.row]……这是一个简短的示例 所以现在问题来了。我有一个集合视图,它有两列mUnberofItemsInSection函数返回这个,我有33行mUnberofSectionsInCollectionView函数返回这个……这意味着我

您知道,在TableView中,您可以设置一个数组,然后将数组的每个元素作为行的文本放置,例如:

我有一个桌面视图

数组:items=[你好,世界,是]

在cellforrowatinexpath函数中,您只需说:cell.text=items[indexPath.row]……这是一个简短的示例

所以现在问题来了。我有一个集合视图,它有两列mUnberofItemsInSection函数返回这个,我有33行mUnberofSectionsInCollectionView函数返回这个……这意味着我有662x33个单元格。我希望每个单元格都显示另一个文本,因此,我制作了一个包含66个元素的字符串数组项。从位置0到位置65…我如何才能像tableview中的示例那样,只写cell.text=items[我不知道在这里写什么]…这是我的问题。我不知道如何识别每个单元格,使它们彼此不同。 我会指定,如果我写:cell.text=items[indexPath.row],它将把数组的第一项放在第一列,把数组的第二项放在第二列,就这样。我也尝试过使用indexPath.item,但它的作用与indexPath.row相同


谢谢你的帮助!这对我有很大帮助

只需将您的项目组织到两个阵列中

override func viewDidLoad() {
    super.viewDidLoad()
    self.items1 = ["hello", "word"]
    self.items2 = ["hello2", "word2"]
    self.itemsSections = [items1, items2]
}
我附上UITableView的示例,但您可以轻松地将其应用于UICollectionView数据源协议 然后在表数据源中使用itemsSections:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return itemsSections.count
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    let section = itemsSections[section]
    return section.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
    let section = itemsSections[indexPath.section]
    cell.text = section[indexPath.row]
    return cell
}

您的数据是如何安排的?您是否有数组数组或字典数组来填充集合视图?