我正在使用Xamarin.Ios和Visual Studio for Mac开发一个课程列表应用程序。
我的主应用程序屏幕是一个ExploreTableView,我目前正在列出我通过适当的Azure移动服务简易表格插入的所有课程。在我的课程中,我有一个有点复杂的自定义单元格,它需要显示“TableView Subject”、"TeacherName“、"Lesson Rating”、"Lesson cost“等变量。我几乎已经成功地实现了所有的功能,并且它是有效的。这里是单元格结构:
我是一名高中IT学生,并不是很擅长xamarin.ios编程,但今天,遵循Youtube微软指南,我还设法实现了Blob存储,我在其中存储了课程封面,我可以检索这些封面,将它们显示在CustomCell的左侧。
问题是,从现在开始,TableView滚动变得非常慢,单元正确地显示了存储在我的Blob Azure存储中的图像,但似乎我在TableView加载单元的方式上做了一些错误的事情。
我试着阅读了一些指南,在堆栈溢出和Microsoft Developer Documentation上,但我真的不能理解缓存系统是如何工作的,以及如何实现它,所以我在这里询问是否有人可以帮助我修复我的代码性能问题,或者建议我一些简单的在线指南。
这是我的ExploreViewController:
using Foundation;
using System;
using System.Collections.Generic;
using UIKit;
using LessonApp.Model;using System.Threading;
using System.Threading.Tasks;
namespace LessonApp.iOS
{
public partial class ExploreViewController : UITableViewController
{
List<LessonsServices> lessonsServices;
public LessonsServices lessonService;
public ExploreViewController(IntPtr handle) : base(handle)
{
lessonsServices = new List<LessonsServices>();
}
public override async void ViewDidLoad()
{
base.ViewDidLoad();
lessonsServices = await LessonsServices.GetLessonsServices();
//lessonsServices = await
TableView.ReloadData();
}
//LISTING ZONE
public override nint RowsInSection(UITableView tableView, nint section)
{
return lessonsServices.Count;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell("servicePreviewCell") as LessonsServicesViewCell;
var lessonService = lessonsServices[indexPath.Row];
//LESSON TITLE
cell.titleLabel.Text = lessonService.Subject + " Lesson"; //e.g. "Math Lesson"
//TEACHER NAME AND LOCATION
cell.teacherNameLocationLabel.Text = lessonService.Teacher + " • " + lessonService.Location;
// PRO TEACHER BADGE
switch (lessonService.IsPro)
{
case true:
cell.proLabel.Hidden = false;
break;
case false:
cell.proLabel.Hidden = true;
break;
default:
cell.proLabel.Hidden = true;
break;
}
cell.startingFromPriceLabel.Text = "Starting from " + lessonService.LowestPrice.ToString() + " €/h";
//Showing Up the Lesson Cover Image in the cell
var bytes = Task.Run(() => ImagesManager.GetImage(lessonService.Id+".jpeg")).Result; //Here I call the GetImage method, which connects to the Blob Storage Container and retrieve the image that has the same ID of the Lesson Service
var data = NSData.FromArray(bytes);
var uiimage = UIImage.LoadFromData(data);
cell.teacherProfileImageView.Image = uiimage;
return cell;
}
//I need this Method to force the cell height
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return 120;
}
//A Segue for another screen, that will copy some information from this page to another
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
{
if (segue.Identifier == "ServiceDescriptionPageSegue")
{
var selectedRow = TableView.IndexPathForSelectedRow;
var destinationViewController = segue.DestinationViewController as ServiceDescriptionView;
destinationViewController.lessonService = lessonsServices[selectedRow.Row];
}
base.PrepareForSegue(segue, sender);
}
}
}
感谢您的关注!
https://stackoverflow.com/questions/50776473
复制相似问题