配置具有相同单元格类型但不同UI样式的UICollectionViewCells

时间:2017-03-30 12:09:07

标签: ios swift user-interface uicollectionview uicollectionviewcell

我的 public void createFolder(ListsSoap ls, String filePathToCreate, String fileName, LoginDO loginDO, HttpServletResponse response) throws Exception { try { String query = ""; String folderName = "NewFolder"; // 1. Prepare Query, Query Options and field Options if (CommonUtilities.isValidStr(folderName)) { // Prepare Query & Query Options for child folders

query = "<Batch OnError=\"Continue\" PreCalc=\"TRUE\" ListVersion=\"0\" " + "RootFolder=\"https://xxx/Shared%20Documents/FPL%20SOs%20-%20JD%20Documents\">" + "<Method ID=\"1\" Cmd=\"New\">" + "<Field Name=\"FSObjType\">1</Field>" +"<Field Name=\"ID\">New</Field>" + "<Field Name=\"BaseName\">" + folderName + "</Field>" + "</Method></Batch>"; } else { // Prepare Query & Query Options for Parent folders query = "<Query><Where><Eq><FieldRef Name=\"FSObjType\" />" + "<Value Type=\"Lookup\">1</Value></Eq></Where></Query>"; } UpdateListItems.Updates updates = null; // 2. Prepare Query, QueryOptions & ViewFields object as per options if (CommonUtilities.isValidStr(query)) { updates = new UpdateListItems.Updates(); updates.getContent().add( sharepointUtil.createSharePointCAMLNode(query)); } // 3. Call Web service to get result for selected options UpdateListItemsResult result = ls .updateListItems(SHAREPOINT_FOLDER_NAME,updates); /* * CommonUtilities * .getApplicationProperty(ApplicationConstants.SHAREPOINT_FOLDER_NAME * ), "", msQuery, viewFields, "", msQueryOptions, ""); */ // 4. Get elements from share point result Element element = (Element) result.getContent().get(0); NodeList nl = element.getElementsByTagName("z:row"); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); System.out.println("Some.!"); } } catch (Exception e) { e.printStackTrace(); } // logger.logMethodEnd(); }` 具有相同的单元格类型,但每个单元格都有不同的UI属性,例如UICollectionViewbackground color ......

我可以在textColor内配置它们,如下所示:

collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

正如您从案例1到5中可以看到具有不同UI属性的相同单元格类型,它根本没有吸引力,也不具有可伸缩性,因此处理此类配置的最佳方法是什么?

2 个答案:

答案 0 :(得分:1)

您需要将数据保存在内存中,因此由于UICollectionViewCell的可重用性,您必须存储单元格的配置。

let dictForCell = ["color":UIColor.redColor(),"isHidden":false] //add key value according to your need
let arrOfCell   = [dictForCell] //also add dictionary of detail

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let dictData = [indexPath.row]
        let cell = collectionView.dequeueReusableCell(forIndexPath: indexPath) as ACollectionViewCell  
        cell.ScoreName.textColor = dictData["color"] as! UIColor
        cell.score.isHidden = dictData["color"] as! Bool        
        cell.score.text = xxx
        cell.score.backgroundColor = xxx
        cell.ScoreName.text = xxx
        return cell
    }

答案 1 :(得分:0)

背景颜色,textColor等应作为变量添加到用于填充该集合视图的对象中。每个对象都有自己的变量,用于自定义单元格。