2012-05-05 66 views
0

嗨,我是iPhone的Xcode开发的新手,我坚持实现历史功能。Xcode基本历史功能

通俗地说我有

4个按钮(每个具有它自己独特的图像)

(按钮1) (按钮2) (按钮3) (按钮4)

(imageview position 2) (imageview position 3) (imageview position 2) (imageview position 4) (imageview position 5)

每次点击一个按钮(最多5次),我需要它显示在适当的图像视图。

即,如果按钮4被按下第一它将在图像视图中显示1 如果按钮3被按下第二它将在图像视图2等

显示我非常感谢一些援助或推在正确的方向。

在此先感谢


更新代码:

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

首先,在厦门国际银行,给每个按钮标签号码可以轻松地找到它:
比方说,你给的1 Button1的标签,BUTTON2是标签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

做一两件事,只是改变的ImageView的按钮click.Use这样的现在的位置,并尝试如果工作通知我们,如果不是我也会提供更多的方法。

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

使用不同的2位置。

+0

这不起作用 – Anthony