开发者

Programmatically done UIImageView not working

I have two views. In the first view I have a table and on selection of a row I call the 2nd view like the following code. The code for the called class is also given. But somehow I can only see the chnaged background and not the other UIImageView that is there. Can anyone please kindly help me out ?? Thanks.

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    details.movieName2=movieName;
    self.title=@"Back";
    [[self navigationController] pushViewController:details animated:NO];    
}

The view class header :

#import <UIKit/UIKit.h>


@interface detailedView : UIViewController {
    NSString *movieName2;
    UIImageView *myImageView;
}

@property (nonatomic, retain) UIImageView *myImageView;
@property (nonatomic, retain) NSString *movieName2;
@end

And the view class code is :

#import "detailedView.h"

@implementation detailedView

@synthesize movieName2;
@synthesize myImageView;

- (id) init {
    self=[super init];
    movieName2=@"";    
    myImageView=[[UIImageView alloc] init];

return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }

    return self;
}

-(void) viewDidAppear:(BOOL)animated
{
    self.view=[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    self.view.frame=CGRectMake(0, 0, 355, 615);
    self.view.backgroundColor开发者_高级运维=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background-retina.png"]];

    self.title=self.movieName2;    

    [myImageView setImage:[UIImage imageNamed:@"sample.png"]];
    [myImageView setFrame:CGRectMake(5, 5, 50, 50)];
    [self.view addSubview:myImageView]; 
}

- (void)dealloc
{
    [myImageView release];
    [movieName2 release];
    [super dealloc];
}

@end


Try setting movie name after you push the detail controller

[[self navigationController] pushViewController:details animated:NO]; 
details.movieName2=[movieName retain];

UPDATE

@Ahsan whatever you are doing is wrong. When you tap on tableViewCell that time you need to allocate second view or if you have already allocated detailsView then why you are allocating a newView in viewDidAppear. Try commenting the line

self.view=[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

and see if it works. The background is works because you are settings the background color by in detailsView itself. The problem is with the allocating a new View and assiging of that view to self.view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜