Ios 如何从didSelectRowAtIndexPath初始化自定义UITableViewCell
我想知道如何获取自定义UITableViewCell的实例,以便将UITextfield设置为第一响应程序 这是我在CellForRowatineXpath中设置自定义单元格的方式Ios 如何从didSelectRowAtIndexPath初始化自定义UITableViewCell,ios,uitableview,uitextfield,Ios,Uitableview,Uitextfield,我想知道如何获取自定义UITableViewCell的实例,以便将UITextfield设置为第一响应程序 这是我在CellForRowatineXpath中设置自定义单元格的方式 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; ce
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomFinishingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
但是,当我试图在DidSelectRowatineXpath内设置所选单元格的实例时,我得到一个错误
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomFinishingCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // error
[cell.widthTexField becomeFirstResponder];
这是我收到的错误
使用类型为“UITableViewCell*”的表达式初始化“CustomFinishingCell*”的指针类型不兼容
您忘记将
cellforrowatinexpath:
返回的UITableViewCell
强制转换到您的子类
CustomFinishingCell *cell = (CustomFinishingCell *)[tableView cellForRowAtIndexPath:indexPath]; // error
此外,我不知道您是否只是在发布的代码中忽略了这一点,但实际上您从未在cellforrowatinexpath:
CustomFinishingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
尝试添加强制转换:
CustomFinishingCell *cell = (CustomFinishingCell*)[tableView cellForRowAtIndexPath:indexPath];
你应该在这行看到一条警告,说做作有问题
initWithStyle
是UITableViewCell
的初始化方法,是否覆盖它并返回CustomFinishingCell
CustomFinishingCell *cell = (CustomFinishingCell*)[tableView cellForRowAtIndexPath:indexPath];
编译器错误,还是运行时错误?关于第二行代码,我认为这行代码cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];在essance做同样的事情。。。你能详细说明一下吗?只是我在选择视图外部的nextUITableViewCell时遇到了问题,因为它没有实例化自己。。所以我会犯错误,我不知道为什么。