Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 比较重用标识符崩溃_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 比较重用标识符崩溃

Ios 比较重用标识符崩溃,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我需要为UITableView中的所有单元格设置自定义单元格高度。在这种方法中: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 我试试这个: if ([[tableView cellForRowAtIndexPath:indexPath] reuseIdentifier] == @"imageCell") 因为我有3个不同的单元,在我的故事板中设置了

我需要为UITableView中的所有单元格设置自定义单元格高度。在这种方法中:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
我试试这个:

if ([[tableView cellForRowAtIndexPath:indexPath] reuseIdentifier] == @"imageCell")
因为我有3个不同的单元,在我的故事板中设置了不同的标识符。然而,我的应用程序只是在这里崩溃,无法访问
EXC\u BAD\u

知道为什么吗


谢谢。

您正在比较一个字符串,因此应该使用
isEqualToString:

if ([[[tableView cellForRowAtIndexPath:indexPath] reuseIdentifier] isEqualToString:@"imageCell"])
(CGFloat)tableView:(UITableView*)表视图行高度索引路径:(NSIndexPath*)索引路径

您应该计算行的高度,而不是获取tableView的单元格

在我看来,在TableView委托的生命周期中,第一步(在分配每个UITableViewCell之前),TableView委托为每一行调用heightForRowAtIndexPath(,但此时未分配UITableViewCell)。在第二步中,TableView调用

(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 创建UitableView单元格


所以你说它崩溃是因为我试图获取一个尚不存在的单元格?heap和“==”来比较2 NSSTring必须被isEqualToString方法替换。事实证明,使用isEqualToString(虽然我理解是正确的),该行仍然会导致应用程序崩溃。