I have tableViewCell having 开发者_如何转开发cell images defined in cellForRowAtIndexPath method like
switch (row) {
case 0:
rowImage=[UIImage imageNamed:@"euro.png"];
cell.imageView.image=rowImage;
break;
case 1:
rowImage=[UIImage imageNamed:@"us.png"];
cell.imageView.image=rowImage;
break;
Now on next view whatever cell user selects i want to show corresponding image on that view which is normal xib file. The image should not cover whole xib file but a tiny place on it
How can i implement that.
Thanks
You can achieve it by creating an array which holds the image names in the same sequence as u have added in the table from 0th row to how much u have added in total. Now in didSelectRowAtIndexPath method pass ther row which is being selected to array's index, like this :
NSString *imgName =[imagesArray objectAtIndex:indexPath.row];
Now you have ur selected image name. You can now pass this name to the next viewcontroller in which u want to display the image. For that just create a method in the next viewcontroller class with string paramter. Pass this image name string to that method. Example,
NSString *localImgName = [getImageName imgName];
where getImageName is the method in the other view controller. Now u can use the obtained imageName in the localImgName variable and use that to set an image to the UIImageView. Hope this helps. I have explained in a programmatic way..
Do this with the help of delegate. In this method,
switch (row) {
case 0:
appDelegate.rowID = 0;
rowImage=[UIImage imageNamed:@"euro.png"];
cell.imageView.image=rowImage;
break;
case 1:
appDelegate.rowID = 1;
rowImage=[UIImage imageNamed:@"us.png"];
cell.imageView.image=rowImage;
break;
rowID is an int in yourAppDelegate file.
//inYourNextViewController.m file
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (yourAppDelegate*) [[UIApplication sharedApplication]delegate];
switch(appDelegate.rowID)
{
case 0:
yourImageView.image = [UIImage imageNamed:image1];
break;
case 1:
yourImageView.image = [UIImage imageNamed:image2];
break;
}
}
精彩评论