2012-05-05 12 views
0

こんにちは、私はiPhone用のXcode開発が初めてで、履歴機能の実装に挑戦しています。素人の観点からXcode基本履歴機能

Iは

4ボタン(独自の画像と各)

(ボタン1) (ボタン2) (ボタン3) (ボタン4)

を有します5画像ビュー

(画像ビュー位置1) (画像ビュー位置2) (画像ビュー位置3) (画像ビューポジション4) (画像ビューポジション5)

ボタンをクリックするたびに(5回まで)、適切な画像ビューで表示する必要があります。ボタン4が最初に押された場合、すなわち、ボタン3が二押された場合、それはなど

イメージ図2で表示される画像ビュー1 で表示される

私はいくつかの支援やプッシュを本当に感謝右方向。事前に

おかげ


アップデートコード:

viewcontroller.h 

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController { 


IBOutlet UIImageView *imageview_history_1; 
IBOutlet UIImageView *imageview_history_2; 
IBOutlet UIImageView *imageview_history_3; 
IBOutlet UIImageView *imageview_history_4; 
IBOutlet UIImageView *imageview_history_5; 

} 

// I would think this could be consolidated into one function 
-(IBAction)showhistory_1; 
-(IBAction)showhistory_2; 
-(IBAction)showhistory_3; 
-(IBAction)showhistory_4; 
-(IBAction)showhistory_5; 

@end 



#import ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 



// function to add to history 
// Need an if/for statement??? 
// On button event 1 display result at image view_history 1, 
// On button event 2 display result at image view_history 2. 

- (IBAction)showhistory_1 { 
UIImage *img = [UIImage imageNamed:@"button1"]; 

[imageview_history_1 setImage:img]; 

} 


@end 

//私は、関数を作成するにこだわっています。再度、感謝します。

あなたはこのように行うことができます
+2

一般的に、この種の質問にはいくつかのコードを含めることをお勧めします。そのため、どこにいるのか、どこにいるのかを知ることができます。 –

+0

こんにちは@RyanPoolosうまくいけば、更新されたコードは私が達成しようとしていることを理解するのに役立ちます。再度、感謝します。 – Anthony

+1

そして、このタイトルはこの質問には正しくないので、そのような投稿のタイトルは使用しないでください。 – vishiphone

答えて

1

まず、あなたのXIBで、簡単に識別するために、各ボタンにタグ番号を与える:
はbutton2をタグである、あなたは1のButton1のタグを与えることにしましょう2、など

私はその後、同じ関数にすべての点にごUIButtonのアクションを変更します

.H:

- (IBAction)show_history:(UIButton)sender; 

.M:

- (void)setNextHistoryImage:(UIImage *)img { 
    if (imageview_history_1.image == nil) { 
     imageview_history_1.image = img; 
    } else if (imageview_history_2.image == nil) { 
     imageview_history_2.image = img; 
    } else if (imageview_history_3.image == nil) { 
     imageview_history_3.image = img; 
    } else if (imageview_history_4.image == nil) { 
     imageview_history_4.image = img; 
    } else if (imageview_history_5.image == nil) { 
     imageview_history_5.image = img; 
    } 
} 

- (IBAction)show_history:(UIButton)sender { 
    NSString *imgName = [NSString stringWithFormat:@"button%d", sender.tag]; 
    UIImage *img  = [UIImage imageNamed:imgName]; 
    [self setNextHistoryImage:img]; 
} 
+0

以下のエラーが表示されます。 'UIImage * __ strong'から 'UIImageView * __ strong'に割り当てられている互換性のないポインタータイプ – Anthony

+0

おっと、ごめんなさい。画像ビューの画像プロパティを参照するようにコードを修正しました。それはそれを処理する必要があります。 – lnafziger

+0

これはあなたを助けましたか? – lnafziger

0

-(IBAction)showhistory_1:(id)sender 
{ 

    if(sender == firstbutton) 
    { 
     UIImage *img = [UIImage imageNamed:@"button4"]; 
     [imageview_history_4 setImage:img]; 
    } 
    else if(sender == secondbutton) 
    { 
     UIImage *img = [UIImage imageNamed:@"button3"]; 
     [imageview_history_3 setImage:img]; 
    } 
    else if(sender == thirdbutton) 
    { 
     UIImage *img = [UIImage imageNamed:@"button2"]; 
     [imageview_history_2 setImage:img]; 
    } 
    else if(sender == fourthbutton) 
    { 
     UIImage *img = [UIImage imageNamed:@"button1"]; 
     [imageview_history_1 setImage:img]; 
    } 
} 
0

一つのことだけで、このようにボタンclick.UseにImageViewののpostionを変更し、私はまた、より多くのメソッドを提供するでしょいない場合、その作業は私達を知らせた場合てみてください。

ImageView.frame=CGRectMake(0, 0, 305, 135); 

は、異なる2位置を使用する。

+0

これは動作しません – Anthony

関連する問題