基本上,我想根据是否按下了烟草段或水烟段,在UITableView中显示所有烟草和所有可用的水烟筒。首先,您应该看到品牌,然后是“产品”(如所有烟草或水烟袋)。 那么现在,firebase数据库的外观应该如何?因为每个产品(虎皮,烟草)都应有一个“名称”,“品牌”,“等级”和“描述”。 第二个问题:如何通过代码在表格视图中接收所有这些信息?现在,我正在为表视图使用以下部分结构,如果它是0或1,则取决于var p。然后,它选择索引0或1(基于单击哪个段)的部分。
var sections = [[Section(brand: "7 Days", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false),
Section(brand: "Zomo", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false)],
[Section(brand: "Aeon", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false),
Section(brand: "Vendetta", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false)]]
What the tableView looks like when its expanded
对于这两个问题中的任何一个,我都非常感谢。 谢谢!
答案 0 :(得分:0)
如果您只是在读取数据,并且永远不会查询任何内容,那么
enum Operation
{
Add,
Multiply,
Power,
UnaryMinus,
None,
}
static class OperationExtensions
{
public static string ToFriendlyString(this Operation me)
{
switch (me)
{
case Operation.None:
return "";
case Operation.Add:
return "+";
case Operation.Multiply:
return "*";
case Operation.Power:
return "^";
case Operation.UnaryMinus:
return "-";
default:
throw new ArgumentException();
}
}
}
class OperationNode
{
public Operation Op;
public OperationNode(Operation op)
{
Op = op;
}
}
interface IVisitor
{
void Visit(OperationNodeLeaf node);
void Visit(OperationNode1 node);
void Visit(OperationNode2 node);
}
sealed class Visitor : IVisitor
{
public string Text { get; set; }
private void Enclose(OperationNode subNode, Operation op)
{
if (subNode.Op < op)
{
Text = Text + "(";
Visit((dynamic)subNode);
Text = Text + ")";
}
else
{
Visit((dynamic)subNode);
}
}
public void Visit(OperationNodeLeaf node)
{
Text = Text + node.Op.ToFriendlyString();
Text = Text + node.Value.ToString();
}
public void Visit(OperationNode1 node)
{
Text = Text + node.Op.ToFriendlyString();
Enclose(node.SubNode, node.Op);
}
public void Visit(OperationNode2 node)
{
Enclose(node.LeftSubNode, node.Op);
Text = Text + node.Op.ToFriendlyString();
Enclose(node.RightSubNode, node.Op);
}
}
class OperationNodeLeaf : OperationNode
{
public int Value;
public OperationNodeLeaf(int v, Operation op = Operation.None) : base(op)
{
Value = v;
}
void Accept(IVisitor v)
{
v.Visit(this);
}
}
class OperationNode1 : OperationNode
{
public OperationNode SubNode;
public OperationNode1(OperationNode sn, Operation op) : base(op)
{
SubNode = sn;
}
void Accept(IVisitor v)
{
v.Visit(this);
}
}
class OperationNode2 : OperationNode
{
public OperationNode LeftSubNode;
public OperationNode RightSubNode;
public OperationNode2(OperationNode lsn, OperationNode rsn, Operation op) : base(op)
{
LeftSubNode = lsn;
RightSubNode = rsn;
}
void Accept(IVisitor v)
{
v.Visit(this);
}
}
class Program
{
static void Main(string[] args)
{
var tree =
new OperationNode2(
new OperationNode2(
new OperationNode2(new OperationNodeLeaf(5), new OperationNodeLeaf(6), Operation.Add),
new OperationNode2(new OperationNodeLeaf(5), new OperationNodeLeaf(6), Operation.Multiply),
Operation.Power
),
new OperationNode2(
new OperationNode2(new OperationNodeLeaf(1), new OperationNodeLeaf(2), Operation.Multiply),
new OperationNode1(new OperationNodeLeaf(7, Operation.None), Operation.UnaryMinus),
Operation.Add
),
Operation.Multiply
);
var visitor = new Visitor();
visitor.Visit(tree);
System.Diagnostics.Debug.WriteLine(visitor.Text);
}
}
但是,例如,如果您要查询所有具有Tabak2产品的品牌,则会导致问题*。因此,这是一种替代方法,使您可以轻松确定具有Tabak2的品牌节点
root
all_data
data_0 //created with .childByAutoId
brand: "7 days"
products:
"Tabak1": true
"Tabak2": true
data_1
brand: "Zomo"
products:
"Tabak1": true
"Tabak2": true
data_3
brand: "Aeon"
products:
"Shisha1": true
"Shisha2": true
如果您想变得超酷,那么这里的结构可以交叉引用所有产品和品牌,从而可以进行各种查询,并使您可以将单个产品链接回多个品牌,反之亦然
root
brands
brand_0
brand: "7 days"
brand_1
brand: "Zomo"
brand_2
brand: "Aeon"
products_by_brand
brand_0
"Tabak1": true
"Tabak2": true
brand_1
"Tabak1": true
"Tabak2": true
brand_2
"Shisha1": true
"Shisha2": true
*这实际上可以通过深度路径查询来实现
答案 1 :(得分:-1)
品牌->产品->烟草-> uniqueId->名称,等级和描述
-> hookah -> uniqueId -> name, rating and description
我不确定您是否需要在产品详细信息中包括该品牌,因为那将是主要的母体。 希望这会有所帮助:)