Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.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
UITableView的Custom Cell.accessoryView仅显示iOS中的第一行_Ios_Cocoa Touch_Uitableview - Fatal编程技术网

UITableView的Custom Cell.accessoryView仅显示iOS中的第一行

UITableView的Custom Cell.accessoryView仅显示iOS中的第一行,ios,cocoa-touch,uitableview,Ios,Cocoa Touch,Uitableview,您好,我需要在我的应用程序中添加自定义单元格访问视图 这是我定制cellAccessorView的代码 self.viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)]; self.lblDay.text = @"Monday"; [self.viewOfAccessory addSubview:self.lblDay]; cell.accessoryView = self.viewOfAccessory

您好,我需要在我的应用程序中添加自定义单元格访问视图

这是我定制cellAccessorView的代码

self.viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)];
self.lblDay.text = @"Monday";
[self.viewOfAccessory addSubview:self.lblDay];
cell.accessoryView = self.viewOfAccessory;
然而,它只显示在第一排。不是在tableView的每一行中

我想做像下面的图片


如何操作?

只能在一个位置添加视图。您正在使用
self.viewOfAccessory
属性定义要显示的内容,然后尝试将其添加到所有单元格中。但是,
self.viewOfAccessory
将只显示在一个位置。如果您将其添加到其他位置(即另一行),它将被移动。您需要创建单独的视图并将其添加到每个单元格。

视图只能添加到一个位置。您正在使用
self.viewOfAccessory
属性定义要显示的内容,然后尝试将其添加到所有单元格中。但是,
self.viewOfAccessory
将只显示在一个位置。如果您将其添加到其他位置(即另一行),它将被移动。您需要创建单独的视图并将它们添加到每个单元格中。

我认为问题可能是因为您将元素作为“self”的一部分调用,然后在“self”(应为tableViewController)中再次添加它们,请尝试以下操作:

UIView* viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)];
//Get the text from lblDay label, check if the "self." is necessary
self.lblDay.text = @"Monday"; //Not sure about this line since I don't have the whole code
[viewOfAccessory addSubview: lblDay];
cell.accessoryView = viewOfAccessory;

我认为问题可能是因为您正在调用元素作为“self”的一部分,然后在“self”(应该是tableViewController)中再次添加它们,请尝试以下操作:

UIView* viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)];
//Get the text from lblDay label, check if the "self." is necessary
self.lblDay.text = @"Monday"; //Not sure about this line since I don't have the whole code
[viewOfAccessory addSubview: lblDay];
cell.accessoryView = viewOfAccessory;

获取这四行的方法是什么?我在UITableView bro的CellForRowatineXpath中编写了上面的代码。奇怪的是,您在
CellForRowatineXpath中设置了访问视图
self.lblDay.text
:这些应该在初始化时只设置一次。只有
单元格。accessoryView
需要在
单元格内设置,以便于RowatineXpath
,并且应该无条件地设置它(即,不仅当“回收”的
单元格
返回一个
nil
时)。粘贴整个CellForRowatineXpath方法。我添加了我想这样做的pic。这四行是用什么方法提取的?我在UtableView bro的CellForRowatineXpath中写了上面的代码。奇怪的是,你在
CellForRowatineXpath
中设置了
访问视图
self.lblDay.text
:这些应该只能在初始化时设置一次。只有
单元格。accessoryView
需要在
单元格中设置,并且应该无条件设置(即,不仅当“回收”的
单元格
返回一个
nil
时)。将整个单元格粘贴到此处。我添加了我想这样做的图片。