作为monotouch.dialog的一部分,动态更改ImageStringElement中的图像

kos*_*kos 1 xamarin.ios monotouch.dialog

我的问题如下:我正在创建一个包含多个ImageStringElements的部分,当选择一个音频文件时,它会播放,例如

Section s = new Section(); 
foreach (var idea in ideas)
{
    s.Add(new ImageStringElement(idea.Id, delegate {ElementTapped();}, playImage));
}
Run Code Online (Sandbox Code Playgroud)

现在当点击其中一个元素时,我想将playImage更改为另一个元素,即PauseImage.然后,当它被选中时,它会变回PlayImage.不知道如何在ElementTapped()方法中执行此操作.基本上我想拥有与语音备忘录应用程序类似的功能.

mig*_*aza 6

您可以继承ImageStringElement并进行两项更改:

加:

class FlippingImageElement : ImageStringElement
{
    UIImage currentImage;
    UITableViewCell currentCell;

    public FlippingImageElement (string caption, UIImage image) : base (caption, image)
    {
        currentImage = image;
    }

    public override UITableViewCell GetCell (UITableView tv)
    {
        var cell = base.GetCell (tv);
        cell.ImageView.Image = currentImage;
        currentCell = cell;
    }

    public void SetImage (UIImage image)
    {
        currentImage = image;
        if (currentCell != null)
            currentCell.ImageView.Image = currentImage;
    }
}
Run Code Online (Sandbox Code Playgroud)

使用此新元素而不是MonoTouch.Dialog,并调用SetImage API来更改图像