开发者

iOS: subviews not added to the parent UIView?

开发者 https://www.devze.com 2023-03-03 13:28 出处:网络
I have a parent UIView with several subviews but these are not visible and they don\'t reconize gestures, so I\'m afraid they have not been added.. or something went wrong.

I have a parent UIView with several subviews but these are not visible and they don't reconize gestures, so I'm afraid they have not been added.. or something went wrong.

The subviews class is ImageWithCaptionView, a subclass of UIView. I've created a ImageWithCaptionView.xib file and wired 2 IBOutlets: UIImageView and UILabel.

I'm sure the xib file is linked with the ImageWithCaptionView class because I've wired the IBOutlets.

What am I doing wrong here ? Why can't I see the subviews ? This is the code:

    ImageWithCaptionView* imageWithCaptionView = [[ImageWithCaptionView alloc] initWithFrame:CGRectMake(offset, 0.0, 320.0, 330.0)];


    UIGestureRecognizer *recognize开发者_如何学Gor = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];

    [(UITapGestureRecognizer *)recognizer setNumberOfTouchesRequired:1];

    imageWithCaptionView.userInteractionEnabled = YES;
    [imageWithCaptionView addGestureRecognizer:recognizer];
    recognizer.delegate = self;
    [recognizer release];

    dispatch_queue_t downloadQueue = dispatch_queue_create("Flickr downloader in EventsTableView", NULL);

    dispatch_async(downloadQueue, ^{

        NSData *image = [FlickrFetcher imageDataFromPhotoId:object]; 

        if(image) {

            //I'm sure this code, inside if statement runs
            imageWithCaptionView.imageView.image = [UIImage imageWithData: image]; 

        }
    });

    imageWithCaptionView.label.text = @"test label"; 


    dispatch_release(downloadQueue);

    [cell addSubview:imageWithCaptionView];
    [imageWithCaptionView release];

thanks

Update, Log:

   2011-05-08 14:34:40.915 FlickrBrowser[26524:207] (null)
   2011-05-08 14:34:40.917 FlickrBrowser[26524:207] {{nan, 2.34559e-38}, {-1.9979, 2.22702e-38}}
   2011-05-08 14:34:40.920 FlickrBrowser[26524:207] (null)
   2011-05-08 14:34:40.923 FlickrBrowser[26524:207] {{5.31614e-36, 5.31614e-36}, {6.74717e-39, 6.74717e


It seems you don't set your subviews' frame anywhere, so they all have zero frame by default and that's why they appear invisible on your parent view.

0

精彩评论

暂无评论...
验证码 换一张
取 消