我在自定义类中有一个异步方法,它返回一个包含字典的NSArray.我试图在UITableView中显示这些数据.一个问题是getGenres方法调用是异步的,因此在显示表之后会加载数据.主要问题是弄清楚如何实现3种数据源方法.在Objective C中,这很简单......
var genreList:NSArray?
override func viewDidLoad() {
super.viewDidLoad()
Bookshop.getGenres {
genres in
self.genreList = genres // copies data to the public NSArray
self.tableView.reloadData() // this returns the data async so need to reload the tableview
println("records: \(self.genreList?.count)") // displays the array of dictionaries correctly
}
}
// #pragma mark - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
return 1
}
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
if self.genreList != nil { …Run Code Online (Sandbox Code Playgroud) 我正在尝试将数据填充到我的表视图中,一切看起来都很好,但仍然没有显示数据。这是代码。一切似乎都很好,但桌面视图没有显示任何内容。连眼睛都不眨一下……
public class MainPage implements Initializable {
@FXML
private AnchorPane root;
@FXML
private Button main_LogOut;
@FXML
private ComboBox<?> main_Clients;
@FXML
private ComboBox<?> main_Users;
@FXML
private TableView<customerDetails> table;
@FXML
private TableColumn<customerDetails, String> clientId;
@FXML
private TableColumn<customerDetails, String> clientName;
@FXML
private TableColumn<customerDetails, String> clientEmail;
@FXML
private TableColumn<customerDetails, String> clientRequirement;
@SuppressWarnings("unchecked")
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
clientId.setCellValueFactory(new PropertyValueFactory<customerDetails,String> ("Id"));
clientName.setCellValueFactory(new PropertyValueFactory<customerDetails, String>("name"));
clientEmail.setCellValueFactory(new PropertyValueFactory<customerDetails, String>("email"));
clientRequirement.setCellValueFactory(new PropertyValueFactory<customerDetails, String>("Requirements"));
table=new TableView<customerDetails>();
table.setItems(getClients());
table.getColumns().addAll(clientId,clientName,clientEmail,clientRequirement);
}
@FXML
void …Run Code Online (Sandbox Code Playgroud) 运行应用程序时出现以下异常时出错.
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FavoriteViewController 0x158d30> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key customCell.'
*** Call stack at first throw:
(
0 CoreFoundation 0x314d0987 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x319a149d objc_exception_throw + 24
2 CoreFoundation 0x314d0705 -[NSException dealloc] + 0
3 Foundation 0x31d28b4f -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 182
4 Foundation 0x31d2803b _NSSetUsingKeyValueSetter + 90
5 Foundation 0x31d29da3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 194
6 Foundation 0x31cdbb17 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 130
7 UIKit 0x33a8860f -[UIRuntimeOutletConnection …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码对tableview进行排序:
list.sort() { $0.points > $1.points }
Run Code Online (Sandbox Code Playgroud)
而且一切正常(一点点),如果我使用这种排序方法,它将对数字(也称为点)进行一直到10的排序。但是,一旦数字超过10,列表就不再排序。而且我不知道如何解决这个问题。
10以下的结果:
10以上的结果:
我猜是因为“ 10”而将其放置在其中,如果我将“ 60”用作它,它将放置在第二或第三位置。那么,我该如何解决呢?我会很感激。