Я пытаюсь добавить изображения в представление и показать им миниатюру в красивой аккуратной строке. Проблема, с которой я сталкиваюсь, заключается в том, что все изображения просто добавляются сверху друг к другу в углу, поскольку только последнее изображение в массиве освобождается.Objective-C добавить миниатюры изображений в конец представления
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.notesField.delegate = self;
NSString *userName = ((ontracAppDelegate*)[UIApplication sharedApplication].delegate).userName;
self.textField.text = [NSString stringWithFormat:@"Date Created: %@ \nCreated By: %@",[NSDate date], userName];
if (self.noteText != nil) {
self.notesField.text = self.noteText;
self.notesField.editable = NO;
self.textLabel.hidden = TRUE;
}
[self.view resignFirstResponder];
if ([self.imageArray count] != 0) {
for (UIImage *image in imageArray) {
NSLog(@"Image %@", image);
[self addImageToScreen:image];
}
}
NSLog(@"imageArray %@", imageArray);
NSLog(@"self.textField.text %@", self.textField.text);
NSLog(@"self.notesField.text %@", self.notesField.text);
}
-(void) addImageToScreen:(UIImage*) image;
{
int adjustHeight = 0;
int adjustWidth = 10;
int imagesInARow = 7;
int imageHeight = 75;
int imageWidth = 75;
int count = [self.imageArray count];
self.numberOfPhotosLabel.text = [NSString stringWithFormat:@"%i",count];
if (count > 1 && count < imagesInARow) {
adjustHeight = 0;
adjustWidth = (20 * [self.imageArray indexOfObject:image]) + ([self.imageArray indexOfObject:image] * imageWidth);
}
UIButton* container = [[UIButton alloc] init ];
CGRect frame = CGRectMake(adjustWidth, 5, imageWidth, imageHeight);
[container setTag:[self.imageArray indexOfObject:image]];
[container setImage:image forState:UIControlStateNormal];
[container setFrame:frame];
[container addTarget:self action:@selector(displayFullScreenImage:) forControlEvents:UIControlEventAllTouchEvents];
UIStackView *photosView = [[UIStackView alloc] initWithFrame:frame];
container.frame = photosView.bounds;
[photosView addSubview:container];
[self.view addSubview:photosView];
}
Где вы добавляете изображение в папку "imageArray"? Из кода я бы предположил, что этот массив всегда пуст. – dasdom
Это добавлено в другом месте, но я проверил массив, и он не пуст. – jampez77
Хорошо, я просто хотел убедиться. Затем проверьте мой ответ. – dasdom