简体   繁体   中英

Display Photo Selected From Gallery into Table View

My current problem is I cant manage to display more than one photo in table view controller B. I try to used array to store the photo URL but my array only can store one URL when I selected the first photo. When i selected another photo my array will only replace the first url to the second and the first url is gone. Below is my code and this question was extending from this question

- (IBAction)organiseAttachement:(id)sender {

// Initialize  View Controller
PhotosListViewController *photoListViewController = [[PhotosListViewController alloc]initWithNibName:@"PhotosListViewController" bundle:nil];
photoListViewController.test = imageURL;
collector = [[NSMutableArray alloc]initWithCapacity:0];
[self.collector addObject:imageURL];
NSLog(@"Collector in root %@",self.collector);
[self.navigationController pushViewController:photoListViewController animated:YES];

}

像这样初始化数组:

collector = [[NSMutableArray alloc] init];

Initialize your array outside of this function. Initialize in viewDidLoad method. That is best for you.

collector = [[NSMutableArray alloc]init];

You are initializing array inside the method. So every time you click on the button, array get initialized. That's why ur first url lost. So keep array initialization outside this method.

collector = [[NSMutableArray alloc] init];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM