新しい開発者です。私は ray wenderlich による Custom Image Picker を使用しています。しかし、私がやりたかったのは、ボタンを押すのではなく、ビューが読み込まれたときにピッカーを表示することです。私はそれを現すことができないようです。これが私がやったことです。何が間違っているのかわかりません。ご協力いただきありがとうございます。
- (void)addImage:(UIImage *)image {
[_images addObject:image];
[_thumbs addObject:[image imageByScalingAndCroppingForSize:CGSizeMake(120, 120)]];
}
- (void) createScrollView {
UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f,0.0f,300.0f,200.0f)];
int row = 0;
int column = 0;
for(int i = 0; i < _thumbs.count; ++i) {
UIImage *thumb = [_thumbs objectAtIndex:i];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*140+24, row*150+10, 100, 100);
[button setImage:thumb forState:UIControlStateNormal];
[button addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[self.view addSubview:view];
[view addSubview:button];
if (column == 6) {
column = 0;
row++;
} else {
column++;
}
}
[view setContentSize:CGSizeMake(1024, (row+1) * 150 + 10)];
}
- (IBAction)buttonClicked:(id)sender {
UIButton *button = (UIButton *)sender;
}
- (void)viewDidLoad
{
[self createScrollView];
_images = [[NSMutableArray alloc] init];
_thumbs = [[NSMutableArray alloc] init];
for(int i = 0; i <= 100; i++)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"images%d.png", i]];
NSLog(@"savedImagePath=%@",savedImagePath);
if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){
[_images addObject:[UIImage imageWithContentsOfFile:savedImagePath]];
NSLog(@"file exists");
}
NSLog(@"file does not exist");
}
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}