我在自定义 UITableViewCell
中有一个“加载更多”UIButton
。我的表也使用了一个代表。单击此按钮时,我想重新加载表格数据。我注意到当我点击按钮时,没有任何反应。但是当我点击按钮周围的区域时,即实际的 Cell,Delegate 获得 RowSelected 事件。
我尝试使用按钮内部事件中的 SetSelected(true,false);
来查看它是否会触发委托(delegate)的 RowSelected 事件,但它没有。
任何人都可以向我解释如何让自定义表格单元格的按钮点击触发实际的 Row Selected 事件吗?如果这不是一个可行的选择,除了将按钮放在自定义表格 View 单元格中之外,是否有更好的方法来“加载更多数据”?
谢谢!
更新: 我确实使用 ContentView.AddSubView,如下面的代码所示。请注意我使用的是 Monotouch,但逻辑是一样的:
public LoadMoreCell (string reuseCellIdentifier)
:base(UITableViewCellStyle.Default, reuseCellIdentifier)
{
SelectionStyle = UITableViewCellSelectionStyle.None;
_btnLoadMore = UIButton.FromType(UIButtonType.RoundedRect);
_btnLoadMore.Frame = new RectangleF(10,5,300,30);
_btnLoadMore.SetTitle("Load More", UIControlState.Normal);
_btnLoadMore.UserInteractionEnabled = true;
ContentView.AddSubview(_btnLoadMore);
}
我有一个 TableDelegate,它有一个 RowSelected 方法,我可以在其中重新加载数据...但是,RowSelected 仅在我单击实际行时才会触发。
最佳答案
我认为您可能已将 uibutton 添加为
[self addSubView:yourButton];
改为使用:-
[self.contentView addSubview:yourButton];
以及自定义单元格的所有其他控件。 在自定义单元格的初始化程序中执行此操作:-
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {}
关于ios - 自定义 UITableViewCell 按钮和 RowSelected (iOS/Monotouch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10650115/