找不到实际的“详细信息按钮”;在 tableView 的行中
当我单击 tableView 的详细信息按钮时...我可以设法获取节号、行号,甚至单元格本身...但是为什么实际的“详细信息按钮”无法获得? (NSLog 始终为按钮显示“(null)”。)
- (void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
int section = indexPath.section;
int row = indexPath.row;
UITableViewCell *aCell = [tableView cellForRowAtIndexPath:indexPath];
UIButton *detailButton = (UIButton *)[aCell accessoryView];
// Why is detailButton null?
NSLog(@"accessory button tapped for row with index path %d x %d \n cell=(%@) \n button=(%@)", section, row, aCell, detailButton);
}
When I click on my tableView's detail-button... I can manage to get the section number, the row number, and even the cell itself... but why is the actual "detail button" unobtainable? (NSLog always displays "(null)" for the button.)
- (void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
int section = indexPath.section;
int row = indexPath.row;
UITableViewCell *aCell = [tableView cellForRowAtIndexPath:indexPath];
UIButton *detailButton = (UIButton *)[aCell accessoryView];
// Why is detailButton null?
NSLog(@"accessory button tapped for row with index path %d x %d \n cell=(%@) \n button=(%@)", section, row, aCell, detailButton);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
附件视图是 UIView 而不是 UIButton。也许将其转换为按钮会导致描述方法失效。只是一个猜测。
The accessory view is a UIView not a UIButton. Perhaps casting it to a button throws off the description method. Just a guess.
最好的选择是访问视图中的按钮。也许像这样
假设您在附件视图中只有详细信息按钮,从子视图中选择它,并在detailBtn中创建对它的引用:)
Your best bet is to access the button within the view. Perhaps something like
This assumes you only have your detail button in the accessory view, picks it out of the subview, and creates your references to it in detailBtn :)