私はかなりIOS開発を始めました。私の最初のクライアントプロジェクトです。複数の画像をテーブルビューに動的に追加
私は、次の場所で立ち往生しています:
ので、10人の誕生日は、今月がある場合は、私が一列に10 imageviews(3枚の絵、写真3枚と1画像)を表示する必要があります。
誰かが私に助けてくれますか?大変感謝しています。
私はかなりIOS開発を始めました。私の最初のクライアントプロジェクトです。複数の画像をテーブルビューに動的に追加
私は、次の場所で立ち往生しています:
ので、10人の誕生日は、今月がある場合は、私が一列に10 imageviews(3枚の絵、写真3枚と1画像)を表示する必要があります。
誰かが私に助けてくれますか?大変感謝しています。
tableviewに画像/ラベル/ボタンを追加したい場合は、最も簡単な方法はUITableViewCellをサブクラス化することです。例えば、5枚の画像(3枚の写真、3枚の写真、1枚の写真が分からない)
がCustomCellという名前のプロジェクトに新しいファイルを追加します。このようなのUITableViewCellのサブクラスでなければなりません:あなたはこのような何か行うことができます表の行にそれらを表示するために
@interface CustomCell : UITableViewCell {
UIImageView *imageView1;
UIImageView *imageView2;
UIImageView *imageView3;
UIImageView *imageView4;
UIImageView *imageView5;
}
@property (nonatomic, retain) UIImageView *imageView1;
@property (nonatomic, retain) UIImageView *imageView2;
@property (nonatomic, retain) UIImageView *imageView3;
@property (nonatomic, retain) UIImageView *imageView4;
@property (nonatomic, retain) UIImageView *imageView5;
@end
をとCustomCell.mでこのコードを次のように入力します。
@synthesize imageView1, imageView2, imageView3, imageView4, imageView5;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 50, 45)];
[self.contentView addSubview:imageView1];
self.imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(65, 8, 50, 45)];
[self.contentView addSubview:imageView2];
self.imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(120, 8, 50, 45)];
[self.contentView addSubview:imageView3];
self.imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(170, 8, 50, 45)];
[self.contentView addSubview:imageView4];
self.imageView5 = [[UIImageView alloc] initWithFrame:CGRectMake(225, 8, 50, 45)];
[self.contentView addSubview:imageView5];
}
return self;
}
はつまり、あなたのビューコントローラでそれらを使用する方法UITableViewCell.Nowのサブクラスで行われ?
あなたはこのようないくつかのことを行うcellForRowAtIndexPathデリゲートメソッドであなたのビューコントローラclass.AndでCustomCell.hをインポートする必要があります。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
//our custom cell
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell.
//cell.imageView1.image = [UIImage imageNamed:@"testImg1"];
//cell.imageView2.image = [UIImage imageNamed:@"testImg2"];
//cell.imageView3.image = [UIImage imageNamed:@"testImg3"];
//cell.imageView4.image = [UIImage imageNamed:@"testImg4"];
//cell.imageView5.image = [UIImage imageNamed:@"testImg5"];
//return cell;
uが良く使用することができました。
NSMutableArray *imgArray = [[NSMutableArray alloc] initWithObjects:cell.imageView1, cell.imageView2,cell.imageView3, cell.imageView4, cell.imageView5, nil];
for (int imageCounter = 0; imageCounter<5; imageCounter++) {
[[imgArray objectAtIndex:imageCounter] setImage:[UIImage imageNamed:[NSString stringWithFormat:@"testImg%d", imageCounter]]];
}
return cell;
}
これはあなたの問題のコンテキストのための非常にプロトタイプの解決策です。
希望すると助かります:)
ご協力いただきありがとうございます。私はそれを試してみると、それが私のために働いた場合は更新されます。 –
ありがとう、これは本当に助けて、私の問題を解決しました:) –
私は助けてくれると嬉しいです – Alok
- (UITableViewCell *)tableView:(UITableView *)tTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
for (int t =0; t<cell.subviews.count; t=t) {
if (![[[cell.subviews objectAtIndex:t].class]isEqualToString:@"UIImageView"]) {
t++;
}
else {
[((UIView*)[[cell.subviews objectAtIndex:t])removeFromSuperview];
}
}
}
for (int t = 0; t<10; t++) {
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(cell.frame.size.width/10*t, 0, cell.frame.size.width/10, cell.frame.size.height)];
[imageView setImage:[UIImage imageNamed:<#(NSString *)#>]];
[cell addSubview:imageView];
}
return cell;
}
(3枚、3枚、1枚の写真)が何を意味するのか分からないが、そこから理解できるはずです。
テーブルビューが行を要求するたびに...毎回...スクロールして戻ってきた行でさえも、彼は10 UIImageのビューを割り当て、それらをサブビューとして積み重ねることを提案しています。漠然とした疑問に対して過度に厳しい刑罰ではないのですか? – danh
古いものを削除したり再利用したりすることもできます。 別のアプローチは、あなたが設定できる10の画像ビューでUITableViewCellのサブクラスを作成することですが、各セルに入れることができる画像は最大10枚必要です。 –
未定義の写真がほしい場合は、私があなたに与えたものを試してみて、ゴミ箱やリメイクではなくオブジェクトを再利用するように修正してください。 使用しない場合http://stackoverflow.com/a/10399483/1354623 –
downvoteの矢印をホバーして、何がダウンボングの理由であるかを確認してから、再度質問を読んでください。ここの人々は、あなたのために仕事をするのではなく、あなたを助けたり、あなたの道を導いたりします。 – psycho
@Vishal Aggarwal: - 詳細を説明するウルの要件..テーブルビューのセルに画像を表示したいですか?またはビューで? テーブルビューのセルに10枚の画像を表示する場合、2つの異なるアプローチを実装する必要があります。 1- URテーブルセルをカスタマイズするには - UITableViewをUITableViewCellのサブビューとして水平にスクロールする - 「Pulse」スタイルのスクロールを作成する。 最初にあなたの要件を詳細に教えてください。その後、私はあなたを助けようとします。私は両方が成功することを願っています:-) –
@psycho - 情報の欠如があなたに怒った場合、私はごめんなさい。私は彼のトレーニングを終えた初心者です。私が学ぶにつれ、確実に良くなるでしょう。 :) –