gpt4 book ai didi

iphone - uitableviewcell 上的附件勾选在某些情况下不显示

转载 作者:行者123 更新时间:2023-12-03 19:58:15 27 4
gpt4 key购买 nike

我有两个表格 View ,一个有多个表格 View 单元格,每个单元格打开相同的 subview ,但用新数据初始化。

表中有大约 100 - 200 个条目,我有一个附属 View ,它是一个勾选,当选择一个单元格时,它会勾选该单元格,然后再次加载主视图。

如果我选择相同的单元格来获取相同的数据集,它将在屏幕中间加载先前选择的单元格(因此它知道其索引路径),但是勾选“取决于列表的深度”将或将不可见..

它往往在表的前 30/40% 左右起作用,但任何低于刻度线的东西都不会可见......也就是说,除非我每次都来回越来越深入,然后有时我可以得到勾选以出现在桌面 View 的较深处。有人知道为什么会发生这种情况吗?

以前有人遇到过这种性质的事情吗?

经过进一步调查,我认为这个方法内部出了问题..

首先,在 subview 中,一旦用户选择一个单元格,就会调用此方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

// Navigation logic may go here. Create and push another view controller.
[self.navigationController popViewControllerAnimated:YES]; //pops current view from the navigatoin stack

//accesses selected cells content
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// now you can use cell.textLabel.text

//This if statment is based off which cell was selected in the parent view so that it knows which cell to pass the data back to
if (parentViewSelectedIndexPath.section == 0) {
if (parentViewSelectedIndexPath.row == 0) {
manufactureCellTextLabel = cell.textLabel.text; //passing label text over to NSString for use with delegate (check "viewwilldissapear")
[[self delegate] setManufactureSearchFields:manufactureCellTextLabel withIndexPath:indexPath]; //This is where I pass the value back to the mainview
}
// a few more If statements for the other methods I can pass data too.


//--- this if block allows only one cell selection at a time
if (oldCheckedData == nil) { // No selection made yet
oldCheckedData = indexPath;
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];

}
else {
UITableViewCell *formerSelectedcell = [tableView cellForRowAtIndexPath:oldCheckedData]; // finding the already selected cell
[formerSelectedcell setAccessoryType:UITableViewCellAccessoryNone];

[cell setAccessoryType:UITableViewCellAccessoryCheckmark]; // 'select' the new cell
oldCheckedData = indexPath;
}
}

这会将索引路径传递给主视图方法...

   - (void) setManufactureSearchFields:(NSString *)cellLabeltext withIndexPath:(NSIndexPath *)myIndexPath
{
manufactureSearchObjectString = cellLabeltext;
manufactureResultIndexPath = myIndexPath;
[self.tableView reloadData]; //reloads the tabels so you can see the value.
}

//然后设置在下一个方法中使用的ManufacturerResultIndexPath,将其传回 subview

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
//--- Idendify selected indexPath (section/row)
if (indexPath.section == 0) {
//--- Get the subview ready for use
VehicleResultViewController *vehicleResultViewController = [[VehicleResultViewController alloc] initWithNibName:@"VehicleResultViewController" bundle:nil];
// ...
//--- Sets the back button for the new view that loads
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil] autorelease];

// Pass the selected object to the new view controller.
[self.navigationController pushViewController:vehicleResultViewController animated:YES];

[vehicleResultViewController setDelegate:self];

if (indexPath.row == 0)
{
vehicleResultViewController.title = @"Manufacture";
[vehicleResultViewController setRequestString:@"ID.xml"]; //sets the request string in searchResultsViewController
vehicleResultViewController.dataSetToParse = @"ID"; // This is used to controll what data is shown on subview... logic
[vehicleResultViewController setAccessoryIndexPath:manufactureResultIndexPath]; //sends indexpath back to subview for accessory tick
vehicleResultViewController.parentViewSelectedIndexPath = indexPath;
}


//etc etc
}

最后我将它传递给 subview 中的方法,该方法将索引路径传递给 oldCheckedData

- (void)setAccessoryIndexPath:(NSIndexPath *)myLastIndexPath
{
oldCheckedData = myLastIndexPath;
[self.tableView reloadData]; //<<---- this is where I reload the table to show the tick...
}

最佳答案

尝试将 cell.accessoryType = 行移动到 willDisplayCell: 委托(delegate)函数,如下所示:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

// You can move this one here too:
cell.selectionStyle = UITableViewCellSelectionStyleNone; // no blue selection

if (indexPath == oldCheckedData) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}

我读到 willDisplayCell: 方法应该用于对单元格进行任何基本的视觉相关修改,例如 selectionStyle/accessoryType,并且cellForRowAtIndexPath:用于单元格数据相关操作的方法,例如设置文本、图像等...

关于iphone - uitableviewcell 上的附件勾选在某些情况下不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7762042/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com