ios – 将按钮添加到UITableViewCell的附件视图
2019年09月04日
作者:佚名
目标:当用户选择单元格时,将向该单元格添加一个按钮.在我的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委托将工作,请先尝试,看看它是否按下按钮触发.)
以上是来客网为你收集整理的ios – 将按钮添加到UITableViewCell的附件视图全部内容,希望文章能够帮你解决ios – 将按钮添加到UITableViewCell的附件视图所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。