ですから、iPhone開発者にとってはかなり新しいものであり、常に学習しています。私は自分が何をしたいのかは知っていますが、どこから始めればよいのかよくわかりません。このプロジェクトの前は、実際にはtableViewアプリしか扱っていなかったので、imageViewとカスタムアクションに関する実際的な知識が非常に不足しています。
UIImageViewに画像をロードしたい(画像はCoreData DBに保存されるため、fetchedResultsControllerによって入力された配列を使用)。
前述のimageViewsの表示画像を制御するアクション「next」のUIButtonとアクション「previous」のUIButtonが必要です。
これまでのところ、DBのマッピングとインターフェイスの設計は行っていますが、これらの点に対するこの答えを見つけることができていません(知っている人にとってはかなり簡単だと確信しています)。
アドバイスやサンプルコードをいただければ幸いです。
DetartrateD
以下の@shawnwallコードスニペット...
-(IBAction)nextImage {
index++;
int imageCount=31;
if (index<=imageCount) {
NSString* imageName=[NSString stringWithFormat:@"img%i.jpg", index];
[picture setImage: [UIImage imageNamed: imageName]];
}
}
viewDidLoadにシードされた可変配列:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Images" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"topImage" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];
NSError *error = nil;
NSMutableArray *mutableFetchResultsT = [[managedObjectContext executeFetchRequest:request error:&error]mutableCopy];
if (mutableFetchResultsT == nil) {
}
[self setTopImageArray:mutableFetchResultsT];
NSLog(@"%i" , [topImageArray count]);
ここで配列に追加される画像:
Images *imageS = (Images *)[NSEntityDescription insertNewObjectForEntityForName:@"Images" inManagedObjectContext:managedObjectContext];
imageS.topImage = selectedImage;
[topImageArray insertObject:imageS.topImage atIndex:0];
NSLog(@"%i" , [topImageArray count]);
.....。
同じ方法ですが、サムネイルを作成した後、次のように呼び出します。
[self updateTopIV];
これは:
-(void)updateTopIV
{
topIV.image = [topImageArray objectAtIndex:0];
}
次に、2つのアクションボタン(次/前)があります。
- (IBAction)nextTouch
{
[self showPhoto:1];
}
- (IBAction)previousTouch
{
[self showPhoto:-1];
}
- (void)showPhoto:(NSInteger)numberToAdd
{
topIV.image = [topImageArray objectAtIndex:currentPhotoIndex + numberToAdd];
}