필요한 것을 구현하기 위해 UITableView를 사용할 수 있습니다. 이것은 샘플입니다. 첫째 마무리에서
이 같은 예제 코드를 호출 할 수 있습니다
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
List<string> dataList = new List<string>();
for (int i = 0; i < 20; i++) {
//Make sure all images is already in the Resources folder
dataList.Add ("test.png");
}
UITableView myTalbeView = new UITableView();
myTalbeView.RowHeight = 80;
myTalbeView.Frame = UIScreen.MainScreen.Bounds;
myTalbeView.AllowsSelection = false;//If you don't want any image be selected, use it.
myTalbeView.SeparatorStyle = UITableViewCellSeparatorStyle.None;//remove the under line
myTalbeView.Source = new MyTableViewSource (dataList);//set source for tableView
this.View.AddSubview (myTalbeView);
}
을 그리고 이것은 MyTableViewSource.cs입니다 :
public class MyTableViewSource : UITableViewSource
{
private static string cellReuseID = "MyTalbeCell";
private List<string> dataList;
public MyTableViewSource(List<string> _dataList)
{
this.dataList = _dataList;
}
public override nint RowsInSection (UITableView tableview, nint section)
{
return dataList.Count;
}
public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
{
MyTableCell cell = tableView.DequeueReusableCell (cellReuseID) as MyTableCell;
if (null == cell)
cell = new MyTableCell (UITableViewCellStyle.Default, cellReuseID);
cell.ImageName = dataList [indexPath.Row];
return cell;
}
}
을 그리고 이것은 MyTalbeCell.cs입니다 :
public class MyTableCell : UITableViewCell
{
private UIImageView imageView;
private string imageName = "";
public string ImageName{
get{
return imageName;
}
set{
imageName = value;
imageView.Image = UIImage.FromFile (imageName);
}
}
public MyTableCell (UITableViewCellStyle style,string reuseID) : base(style,reuseID)
{
imageView = new UIImageView();
this.AddSubview (imageView);
}
public override void LayoutSubviews()
{
imageView.Frame = this.Bounds;
}
}
희망이 당신을 도울 수 있기를 바랍니다.
아직 도움이 필요하시면 여기로 질문을 남겨 두십시오. 후자를 확인하겠습니다.
내 질문에 훌륭한 솔루션을 제공 한 것은 이번이 두 번째입니다. 우수 코드 예제로 명확하고 간결한 대답. 나는 일하는 것을 좋아한다. 고맙다. –
당신은 Xamarin으로 발전하는 것을 즐긴다. –