0

I'm trying to use the Three20 TTPhotoViewController with MonoTouch. I've derived FacebookPhoto from TTPhoto and FacebookPhotoSource from TTPhotoSource and am now trying to invoke the TTPhotoViewController but I get the following exception when pushing the view controller:

Objective-C exception thrown. Name: NSInvalidArgumentException Reason: * -[NSPlaceholderString initWithFormat:locale:arguments:]: nil argument

I noticed that the monotouch bindings in this github project: https://github.com/mono/monotouch-bindings/tree/492f68c3c2007f0638452cc8a5a762556db224ba/Three20/binding were missing the photoAtIndex binding, so I added that and recompiled them, but I haven't been able to figure out why I am getting this exception.

Here is how I'm invoking the TTPhotoViewController:

List<Photo> photoList = FacebookGraphApi.Instance.GetAlbumPhotos(album.id);
List<FacebookPhoto> fbPhotoList = photoList.Select(x => new FacebookPhoto(x)).ToList();
var photos = new TTPhotoViewController();
photos.PhotoSource = new FacebookPhotoSource(fbPhotoList);
NavController.PushViewController(photos, true);

Here is the definition of the TTPhotoSource

    class FacebookPhotoSource : TTPhotoSource
    {
        List<FacebookPhoto> _photoList;

        public FacebookPhotoSource (List<FacebookPhoto> photoList)
        {
            _photoList = photoList;
            int i = 0;
            foreach (FacebookPhoto photo in photoList) {
                photo.PhotoSource = this;
                photo.Index = i++;
            }
        }

        public override string Title {
            get {
                return "Facebook Photos";
            }
            set  {
                throw new NotImplementedException();
            }
        }

        public override int NumberOfPhotos {
            get {
                return _photoList.Count;
            }
        }

        public override int MaxPhotoIndex {
            get {
                return _photoList.Count -1;
            }
        }

        public override TTPhoto PhotoAtIndex(int photoIndex)
        {
            return _photoList[photoIndex];
        }

    }

and here is the definition of the FacebookPhoto:

    class FacebookPhoto : TTPhoto
    {
        Photo _photo;
        public FacebookPhoto(Photo photo)
        {
            _photo = photo;
        }

        public override string Caption {
            get {
                if(_photo.name == null)
                    return "";
                return _photo.name;
            }
            set {
                throw new NotImplementedException();
            }
        }

        public override TTPhotoSource PhotoSource { get; set; }

        public override int Index { get; set; }

        public override SizeF Size {
            get {
                return new SizeF(_photo.width, _photo.height);
            }
            set {
                throw new NotImplementedException();
            }
        }

        public override string URLForVersion (int version)
        {
            switch (version) {
            case 4:
                return _photo.picture;
            default:
                return _photo.source;
            }
        }
    }
4

0 回答 0