1

My problem is as follows: I am creating a section with a number of ImageStringElements that when selected an audio file will play, eg

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

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

4

1 回答 1

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;
    }
}

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

于 2012-01-27T14:19:24.723 回答