【发布时间】:2023-03-18 00:03:01
【问题描述】:
我正在使用 Unity3D 资源为我的应用程序创建一个 TableView。但是,当我尝试在 for-each 循环中从一个对象移动到另一个对象时,它只显示响应中的最后一个对象。这就是我的意思:
这是我尝试创建单元格的代码(仅供参考,我使用 GameSparks 作为后端服务):
//Will be called by the TableView to know how many rows are in this table
public int GetNumberOfRowsForTableView (TableView tableView)
{
return 10;
}
//Will be called by the TableView to know what is the height of each row
public float GetHeightForRowInTableView (TableView tableView, int row)
{
return (m_cellPrefab.transform as RectTransform).rect.height;
}
//Will be called by the TableView when a cell needs to be created for display
public TableViewCell GetCellForRowInTableView (TableView tableView, int row)
{
LeaderboardCell cell = tableView.GetReusableCell (m_cellPrefab.reuseIdentifier) as LeaderboardCell;
if (cell == null) {
cell = (LeaderboardCell)GameObject.Instantiate (m_cellPrefab);
new GameSparks.Api.Requests.LeaderboardDataRequest ().SetLeaderboardShortCode ("High_Score_Leaderboard").SetEntryCount (100).Send ((response) => {
if (!response.HasErrors) {
resp = response;
Debug.Log ("Found Leaderboard Data...");
} else {
Debug.Log ("Error Retrieving Leaderboard Data...");
}
});
}
foreach (GameSparks.Api.Responses.LeaderboardDataResponse._LeaderboardData entry in resp.Data) {
int rank = (int)entry.Rank;
//model.Rank =rank;
string playerName = entry.UserName;
cell.name = playerName;
string score = entry.JSONData ["SCORE"].ToString ();
cell.SetScore(score);
//string fbid = entry.ExternalIds.GetString("FB").ToString();
//model.facebookId = fbid;
Debug.Log ("Rank:" + rank + " Name:" + playerName + " \n Score:" + score);
}
return cell;
}
【问题讨论】:
标签: c# android ios unity3d tableview