Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.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
Ios 触摸和释放后,数据将从UITableView中消失_Ios_Uitableview - Fatal编程技术网

Ios 触摸和释放后,数据将从UITableView中消失

Ios 触摸和释放后,数据将从UITableView中消失,ios,uitableview,Ios,Uitableview,UITableView数据在触摸时消失,如下面的屏幕截图所示 第一次加载视图时,数据将正确加载,如下所示 触摸屏幕然后释放时,数据消失。如果我按住,数据仍然存在 我在UITableView自定义类中设置了一个断点,并注意到在加载视图时会调用CellForRowatineXpath:中的方法,但在触摸之后不会调用。从未调用DidSelectRowatineXpath:方法 代码与示例非常相似。我正在尝试加载一个日期选择器,该日期选择器配置为仅在触摸单元格时显示时间 下面是相关代码,以及IB委托和数

UITableView数据在触摸时消失,如下面的屏幕截图所示

第一次加载视图时,数据将正确加载,如下所示

触摸屏幕然后释放时,数据消失。如果我按住,数据仍然存在

我在UITableView自定义类中设置了一个断点,并注意到在加载视图时会调用CellForRowatineXpath:中的方法,但在触摸之后不会调用。从未调用DidSelectRowatineXpath:方法

代码与示例非常相似。我正在尝试加载一个日期选择器,该日期选择器配置为仅在触摸单元格时显示时间

下面是相关代码,以及IB委托和数据源连接的屏幕截图。如果你需要更多的信息,请告诉我。我是iOS新手,因此我非常感谢尽可能详细地介绍可能的原因和解决方案

@interface ScheduleTableViewController ()

@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) NSDateFormatter *timeFormatter;
@property (nonatomic, strong) NSIndexPath *timePickerIndexPath;
@property (assign) NSInteger pickerCellRowHeight;
@property (nonatomic, strong) IBOutlet UIDatePicker *pickerView;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *doneButton; //to be used later for ios 6 compatability

@end



@implementation ScheduleTableViewController

- (void)viewDidLoad
{
[super viewDidLoad];

NSMutableDictionary *itemOne = [[@{ kPeriodKey : @"     Tap a cell to change the survey time: " } mutableCopy ] autorelease];
NSMutableDictionary *itemTwo = [[@{ kPeriodKey : @"Morning Survey",
                                   kTimeKey  : [NSDate date] } mutableCopy] autorelease];
NSMutableDictionary *itemThree = [[@{ kPeriodKey : @"Evening Survey",
                                     kTimeKey  : [NSDate date] } mutableCopy] autorelease];
self.dataArray = @[itemOne, itemTwo, itemThree];

self.timeFormatter = [[[NSDateFormatter alloc] init] autorelease];
[self.timeFormatter setDateFormat:@"h:mm a"];
[self.timeFormatter setDateStyle:NSDateFormatterNoStyle];
[self.timeFormatter setTimeStyle:NSDateFormatterShortStyle];

UITableViewCell *pickerViewCellToCheck = [self.tableView dequeueReusableCellWithIdentifier:kTimePickerID];
self.pickerCellRowHeight = pickerViewCellToCheck.frame.size.height;

[self.tableView setDelegate:self];
}



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

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.reuseIdentifier == kDayPeriodAndTimeCellID) {
    // todo check for ios < 7.0

    [self displayInlineTimePickerForRowAtIndexPath:indexPath];

} else {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;

NSString *cellID = kDayPeriodAndTimeCellID;

if ([self indexPathHasPicker:indexPath]) {
    cellID = kTimePickerID;
}

cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];

if (indexPath.row == 0) {
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

NSInteger modelRow = indexPath.row;
if (self.timePickerIndexPath != nil && self.timePickerIndexPath.row < indexPath.row) {
    modelRow--;
}

NSDictionary *itemData = self.dataArray[modelRow];

if ([cellID isEqualToString:kDayPeriodAndTimeCellID]) {
    cell.textLabel.text = [itemData valueForKey:kPeriodKey];
    cell.detailTextLabel.text = [self.timeFormatter stringFromDate:[itemData valueForKey:kPeriodKey]];
}

return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([self hasInlineTimePicker]) {
    NSInteger numRows = self.dataArray.count;
    return ++numRows;
}

return self.dataArray.count;

}
我将添加到一个现有的应用程序中,因此所有现有的UI都是在XIB文件中实现的,但是这个表是在故事板中实现的。下面是代理和数据源出口连接的屏幕截图


我认为你需要在这里提供更多的上下文,但我有一个猜测。UITableView需要一个UITableViewDataSource来告诉它单元格中应该包含哪些数据。你把它挂在XIB上了吗?如果是这样,我看不到ScheduleTableViewController中实现的任何方法

确保实现该协议,特别是tableView:CellForRowatineXpath:方法。这是您实际配置表格视图中显示的单元格的位置


听起来像是您在InterfaceBuilder中创建了原型表格单元。对于创建的每个原型单元,请确保在“属性检查器”中设置其单元标识符。然后使用此单元格标识符来标识在调用tableView:CellForRowatineXpath:时正在配置的单元格。

您是否尝试过使用函数设置表数据

numberOfSectionsInTableView:tableView
tableView:tableView numberOfRowsInSection:section

我在斯威夫特也有类似的问题。通过将实例变量放入负责显示tableView的tableViewManager,解决了这个问题。最初,它的一个实例是通过按钮操作方法创建和调用的。所以它是由ARC解除分配的,所以当我试图与它交互时,tableView就消失了。
灵感来源:

在我的案例中,我使用的是SwipeMenuViewController

每一页都有一个表格视图。 当我单击选项卡时,它会毫无问题地切换表。但当我触摸桌子时,数据消失了 表格存在,我用背景色检查

我的解决方案是保留对SwipMenuViewController方法返回的UIViewController的引用:

func swipeMenuView\uuSwipeMenuView:swipeMenuView,ViewControllerFormat索引:Int->UIViewController{ ViewController[index.description]=baseContactsTableViewController 返回基本联系人StableViewController
}

您的CellForRow索引路径代码在哪里?从我看到的情况来看,您似乎是从自动删除的对象而不是保留的对象加载表数据。我最近在运行analyze之后添加了autorelease,analyze报告了item*变量的潜在内存泄漏。添加autorelease之前也存在相同的问题。如果dequeueReusableCell无法返回单元格,则需要创建cell@rocky对于正在使用的方法来说,情况并非如此。如果在atoryboard中为重用标识符注册了类或nib,则此处使用的方法将始终返回一个单元格。无需检查是否为nil并将其恢复。只需添加CellForRowatineXpath的代码。我假设,由于数据最初是正确填充的,所以数据源配置正确,或者我是不是偏离了基准?。正确,原型单元构建在故事板中。我仔细检查了单元格标识符,它们配置正确。interface builder中的“identifier”文本框与我拥有的两个原型单元格的代码中的“identifier”文本框相匹配。每个tableview都必须有一个数据源。仅创建原型单元不满足此要求。原型单元就是表准备好由数据源配置的单元。但是,数据源必须在那里告诉表要显示多少行以及如何配置每个单元格。dataArray属性就是数据源。我在viewDidLoad中将项目加载到数组中,并在CellForRowatineXpath中从中提取。是否有明确的方法将其配置为数据源?在任何情况下,不幸的是,当触摸单元格时,不会调用CellForRowatineXpath方法。数据源必须是实现UITableViewDataSource协议的对象。另请参见,尝试将数据数组简化为常规NSString对象。并确保每次调用“CellForRowatineXpath:”时,数据数组中的数据可用。那些是易变的 临时声明看起来有点可疑。。。祝你好运刚刚把numberOfRowsInSection的代码贴了出来。NumberOfSectionsTableView默认为1,等于我拥有的节数,因此我没有实现该函数。