简体   繁体   English

插入带有类别的TableView单元格

[英]Insert TableView cell with categories

I am developing and application that has a tableview, and I am able to insert new cells dynamically. 我正在开发具有表视图的应用程序,并且能够动态插入新单元格。 The problem is that the tableview needs to have categories for something like color or shape, my question is: 问题是,tableview需要具有诸如颜色或形状之类的类别,我的问题是:

When I am adding a new cell how can I choose in wish category the cell will be? 添加新单元格时,如何在愿望类别中进行选择?

I know that I have to build my database in a certain way but the problem is that im no good with coredata and im a bit confused with the topic, so if someone could give me some explanation or sample code I would be very thankful. 我知道我必须以某种方式来构建数据库,但是问题是我对coredata不好,并且对主题有点困惑,所以如果有人可以给我一些解释或示例代码,我将非常感激。

Best Regards. 最好的祝福。

If you setup your datasource right, then you could retrieve an object with the desired category in it. 如果正确设置数据源,则可以检索其中具有所需类别的对象。 When you retrieve that object in the cellForRowAtIndexpath: you will then extract that category and use it in some sort of switch statement which allows you to alter the cell with the desired shape and color and all you want. 当您在cellForRowAtIndexpath:检索该对象时cellForRowAtIndexpath:然后,您将提取该类别并在某种switch语句中使用它,该语句可让您使用所需的形状和颜色以及所需的所有内容更改单元格。

For cleaner code however I suggest to make a custem cell and call some sort of update-method (in the same cellforrowatindexpath: ) which does the same visual stuff for you. 但是,对于更干净的代码,我建议创建一个自定义单元格并调用某种更新方法(在同一cellforrowatindexpath: ),该方法可以为您提供相同的视觉效果。

What you do with the database or whatever should be seen apart from this matter since you should fetch that data in some other class. 您应该对数据库执行的操作或与此无关的其他操作,因为您应该在其他类中获取该数据。 Which then will be shaped into your custom object which will then be put in your datasource. 然后将其成形为您的自定义对象,然后将其放入您的数据源中。

Without some specifics in your question however this won't be more then theoretical shizzle. 如果您的问题中没有一些具体细节,那么这将不只是理论上的混乱。

However you should be able to figure this out. 但是,您应该能够弄清楚这一点。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM