Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Xcode基本历史函数_Iphone_Xcode_Ios4_Uiimageview_Xcode4.2 - Fatal编程技术网

Iphone Xcode基本历史函数

Iphone Xcode基本历史函数,iphone,xcode,ios4,uiimageview,xcode4.2,Iphone,Xcode,Ios4,Uiimageview,Xcode4.2,嗨,我是iPhone Xcode开发的新手,我一直在实现历史记录功能 用外行的话说,我有 4个按钮(每个按钮都有自己独特的图像) (按钮1) (按钮2) (按钮3) (按钮4) 和5个图像视图 (图像视图位置1) (图像视图位置2) (图像视图位置3) (图像视图位置4) (图像视图位置5) 每次点击一个按钮(最多5次),我需要它显示在适当的图像视图 i、 e如果首先按下按钮4,则它将显示在图像视图1上 如果第二次按下按钮3,它将显示在图像视图2等处 我真的很希望能得到一些帮助或朝着正确的方向努

嗨,我是iPhone Xcode开发的新手,我一直在实现历史记录功能

用外行的话说,我有

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

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

和5个图像视图

(图像视图位置1) (图像视图位置2) (图像视图位置3) (图像视图位置4) (图像视图位置5)

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

i、 e如果首先按下按钮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
viewcontroller.h
#进口
@界面ViewController:UIViewController{
IBUIImageView*imageview_历史_1;
IBUIImageView*imageview_历史_2;
IBUIImageView*imageview_历史_3;
IBUIImageView*imageview_历史_4;
IBUIImageView*imageview_历史_5;
}
//我认为这可以整合为一个功能
-(iAction)showhistory_1;
-(iAction)showhistory_2;
-(iAction)showhistory_3;
-(i)展示历史4;
-(i行动)展示历史5;
@结束
#导入ViewController.h“
@界面视图控制器()
@结束
@实现视图控制器
//要添加到历史记录的函数
//需要if/for语句吗???
//在按钮事件1上,在图像视图_历史记录1上显示结果,
//On按钮事件2在图像视图_历史记录2显示结果。
-(iAction)showhistory_1{
UIImage*img=[UIImage ImageName:@“button1”];
[imageview_history_1 setImage:img];
}
@结束
//我一直在创建函数。再次感谢。

您可以这样做:

-(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];
   }
}

首先,在您的xib中,为每个按钮提供一个标签号,以便于识别:
假设你给button1一个标签1,button2是标签2,以此类推

然后,我会将您的UIButton操作更改为所有指向相同功能的操作:

.h:

.m:


做一件事,只需更改按钮单击时imageview的位置。像这样使用并尝试,如果它的工作通知我们,如果没有,我还将提供更多的方法

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

使用不同的-2位置。

一般来说,为此类问题添加一些代码是一个好主意,这样我们就知道你在哪里,我们需要带你去哪里。嗨@RyanPoolos,希望更新的代码有助于理解我试图实现的目标。再次感谢。不要使用这样的帖子标题,因为该标题不适合此任务ion。我收到以下错误从“UIImage*\uuuuu strong”中分配给“UIImageView*\uuuu strong”的不兼容指针类型,很抱歉。已更正代码以引用图像视图的图像属性。这应该会解决它。对响应延迟表示歉意,是的。感谢您的帮助。我的游戏已提交到app store。我将这里没有链接,那里也没有。再次感谢
- (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];
}
  ImageView.frame=CGRectMake(0, 0, 305, 135);