目标:当用户选择单元格时,将向该单元格添加一个按钮.在我的didSelectRowAtIndexPath函数中,我有以下内容:
UIButton *downloadButton = [[UIButton alloc] init]; downloadButton.titleLabel.text = @"Download"; [downloadButton setFrame:CGRectMake(40,100,20)]; [[self.tableView cellForRowAtIndexPath:indexPath].accessoryView addSubview:downloadButton]; [[self.tableView cellForRowAtIndexPath:indexPath].accessoryView setNeedsLayout]; [downloadButton release];
不幸的是,似乎没有做任何事情.我是否重新修复细胞校正?我需要添加另一种方式吗?
解决方法
尝试这个代码块而不是上面提供的块
UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [downloadButton setTitle:@"Download" forState:UIControlStateNormal]; [downloadButton setFrame:CGRectMake(0,35)]; [tableView cellForRowAtIndexPath:indexPath].accessoryView = downloadButton;
这应该显示按钮,但是您仍然需要使用addTarget连接某些选择器. (我不知道如果在这个例子中听的附件ButtonTappedForRowWithIndexPath委托将工作,请先尝试,看看它是否按下按钮触发.)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。