
一般的话- (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath 这个方法里应该都会设置cell内的显示内容,在didselect里面你把上面那个方法里的[xxxx objectAtIndex:indexPathrow] xxxxx]再次赋给你自己要取指的对象不就可以了么
TableView的数据填充,需要一个ObservableList。其中需要一个类来做数据填充。
下面看看我们数据填充的类:
复制代码代码如下:
import javafxbeanspropertySimpleDoubleProperty;
import javafxbeanspropertySimpleStringProperty;
/
@author wing
/
public final class DownloadData {
private final SimpleStringProperty fileName = new SimpleStringProperty();
private final SimpleStringProperty status = new SimpleStringProperty();
private final SimpleStringProperty dlSpeed = new SimpleStringProperty();
private final SimpleDoubleProperty progress = new SimpleDoubleProperty();
private final SimpleStringProperty downloadSize = new SimpleStringProperty();
private final SimpleStringProperty dlPercent = new SimpleStringProperty();
private String uuid;
public DownloadData(String filename, double progress) {
setFileName(filename);
setProgress(progress);
}
public DownloadData(String status, String filename, String dlSpeed, double progress) {
setStatus(status);
setFileName(filename);
setDlSpeed(dlSpeed);
setProgress(progress);
}
/
@return the fileName
/
public String getFileName() {
return fileNameget();
}
/
@param fileName the fileName to set
/
public void setFileName(String fileName) {
thisfileNameset(fileName);
}
public SimpleStringProperty fileNameProperty(){
return fileName;
}
/
@return the status
/
public String getStatus() {
return statusget();
}
/
@param status the statusto set
/
public void setStatus(String status) {
thisstatusset(status);
}
public SimpleStringProperty statusProperty(){
return status;
}
/
@return the String
/
public String getDlSpeed() {
return dlSpeedget();
}
/
@param dlSpeed the dlSpeed to set
/
public void setDlSpeed(String dlSpeed) {
thisdlSpeedset(dlSpeed);
}
public SimpleStringProperty dlSpeedProperty(){
return dlSpeed;
}
/
@return the progress
/
public double getProgress() {
return progressget();
}
/
@param progress the progress to set
/
public void setProgress(double progress) {
thisprogressset(progress);
}
public SimpleDoubleProperty progressProperty(){
return progress;
}
public String getDownloadSize() {
return downloadSizeget();
}
public void setDownloadSize(String downloadSize) {
thisdownloadSizeset(downloadSize);
}
public SimpleStringProperty downloadSizeProperty(){
return downloadSize;
}
public String getDlPercent() {
return dlPercentget();
}
public void setDlPercent(String dlPercent) {
thisdlPercentset(dlPercent);
}
public SimpleStringProperty dlPercentProperty(){
return dlPercent;
}
public String getUUID() {
return uuid;
}
public void setUUID(String uuid) {
thisuuid = uuid;
}
}
记住,用作数据填充的类,一定要用JavaFX的Property机制,可以进行数据绑定,这样在我们改变ObservableList的时候,TableView的数据才会实时刷新。
复制代码代码如下:
private final ObservableList<DownloadData> data
= FXCollectionsobservableArrayList();
ObservableList<TableColumn> observableList = mDownloadTablegetColumns();
observableListget(0)setCellValueFactory(new PropertyValueFactory("status"));
observableListget(1)setCellValueFactory(new PropertyValueFactory("fileName"));
observableListget(2)setCellValueFactory(new PropertyValueFactory("dlSpeed"));
observableListget(3)setCellValueFactory(new PropertyValueFactory("downloadSize"));
observableListget(4)setCellValueFactory(new PropertyValueFactory("progress"));
observableListget(4)setCellFactory(ProgressBarTableCellforTableColumn());
observableListget(5)setCellValueFactory(new PropertyValueFactory("dlPercent"));
mDownloadTablesetItems(data);
我们通过TableViewgetColumns来获取TableView的所有列。
CellValueFactory指的是TableView每一列里填充的数据。我们这里简单的使用PropertyValueFacotry。后面的要对应你DownloadData中的Property属性名。
CellFactory我们可以指定TableView中某一个Cell的视图类型。大家可以看到我用到了个ProgressBar。
另外CellFactory,JavaFX中自带部分的CellFactory,详细的大家可以在javafxscenecontrolcell包中找到。
接着我们通过创建DownloadData,设置数据,并添加到ObservableList中即可。
*** 作方法: UITableView加载的顺序是先得到表的行的高度,也就是先调用heightForRowAtIndexPath方法,然后再调用cellForRowAtIndexPath,所以我们有两个办法实现自定义cell高度: 一:改变它的加载顺序,或者说白了就是计算好cell高度后
以上就是关于如何获取点击的UITableView的cell的内容全部的内容,包括:如何获取点击的UITableView的cell的内容、javafx tableview与ObservableList进行数据双向绑定、自定义的UITableViewcell的高度怎么获取等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)