Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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 如何检查正在调用imageview中的哪个图像_Iphone_Objective C_Sqlite - Fatal编程技术网

Iphone 如何检查正在调用imageview中的哪个图像

Iphone 如何检查正在调用imageview中的哪个图像,iphone,objective-c,sqlite,Iphone,Objective C,Sqlite,我有2个图像视图,其中包含图像。我希望当我点击第一个图像时,图像应该被选中,如果它被选中,它应该返回值TRUE或1,该值应该保存在sqlite数据库中。这是怎么可能的?您使用触摸事件。捕获触摸点并执行您的操作。这里我将为您提供一个执行此操作的示例结构 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject];

我有2个图像视图,其中包含图像。我希望当我点击第一个图像时,图像应该被选中,如果它被选中,它应该返回值TRUE或1,该值应该保存在sqlite数据库中。这是怎么可能的?

您使用触摸事件。捕获触摸点并执行您的操作。这里我将为您提供一个执行此操作的示例结构

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];

    CGPoint location= [touch locationInView:self.view];

    if(CGRectContainsPoint(firstImage.frame, location)) {
        //set some flag like
        selectionFlag=1;        }
    else if(CGRectContainsPoint(secImage.frame, location)){
        selectionFlag=2;        }
    }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

        UITouch  *touch = [[event allTouches] anyObject]; 
        CGPoint location = [touch locationInView:self.view];

        if(CGRectContainsPoint(firstImage.frame, location)) {   
            if(selectionflag==1) {
                //do ur db actions              }
        }
        else if(CGRectContainsPoint(secImage.frame, location))  {       
            if(selectionflag==2) {
            //do ur db actions                }
        }
        selectionflag=0; 
    }

你进行触摸事件。捕捉触摸点并执行你的动作。这里我将给你一个示例结构来实现这一点

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];

    CGPoint location= [touch locationInView:self.view];

    if(CGRectContainsPoint(firstImage.frame, location)) {
        //set some flag like
        selectionFlag=1;        }
    else if(CGRectContainsPoint(secImage.frame, location)){
        selectionFlag=2;        }
    }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

        UITouch  *touch = [[event allTouches] anyObject]; 
        CGPoint location = [touch locationInView:self.view];

        if(CGRectContainsPoint(firstImage.frame, location)) {   
            if(selectionflag==1) {
                //do ur db actions              }
        }
        else if(CGRectContainsPoint(secImage.frame, location))  {       
            if(selectionflag==2) {
            //do ur db actions                }
        }
        selectionflag=0; 
    }
先做

[self.*yourimageViewname* setUserEnteractionEnabled:YES];
BOOL select1,secelect2;
select1=NO;
select2=NO;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {

 UITouch *touch=[touches anyObject];
 CGPoint touchLocation = [touch locationInView:touch.view];
//give the beginning and ending x and y points in condition to check which imageView is taped

 if(touchLocation.x>1 && touchLocation.x<116 && touchLocation.y>133 && touchLocation.y<233)
 {
select1=YES;
}
else if(touchLocation.x>120 && touchLocation.x<300 && touchLocation.y>133 && touchLocation.y<233)
 {
select2=YES;
} 
}

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
  }
[self.*yourimageViewname*setUserEnteractionEnabled:YES];
BOOL select1,secelect2;
选择1=否;
选择2=否;
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件
{
UITouch*touch=[触摸任何对象];
CGPoint touchLocation=[触摸位置视图:touch.view];
//将开始和结束的x点和y点置于适当的条件下,以检查哪个imageView已录制
如果(touchLocation.x>1&&touchLocation.x133&&touchLocation.y120&&touchLocation.x133&&touchLocation.y第一次执行

[self.*yourimageViewname* setUserEnteractionEnabled:YES];
BOOL select1,secelect2;
select1=NO;
select2=NO;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {

 UITouch *touch=[touches anyObject];
 CGPoint touchLocation = [touch locationInView:touch.view];
//give the beginning and ending x and y points in condition to check which imageView is taped

 if(touchLocation.x>1 && touchLocation.x<116 && touchLocation.y>133 && touchLocation.y<233)
 {
select1=YES;
}
else if(touchLocation.x>120 && touchLocation.x<300 && touchLocation.y>133 && touchLocation.y<233)
 {
select2=YES;
} 
}

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
  }
[self.*yourimageViewname*setUserEnteractionEnabled:YES];
BOOL select1,secelect2;
选择1=否;
选择2=否;
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件
{
UITouch*touch=[触摸任何对象];
CGPoint touchLocation=[触摸位置视图:touch.view];
//将开始和结束的x点和y点置于适当的条件下,以检查哪个imageView已录制

如果(touchLocation.x>1&&touchLocation.x133&&touchLocation.y120&&touchLocation.x133&&touchLocation.y使用触摸是下面答案中解释的一种方式。如果您只有两个imageview,您还可以尝试在该imageview的顶部有两个自定义透明按钮,因此您可以根据t轻松知道触摸哪个图像您为按钮提供的标签。

使用触摸是下面答案中解释的一种方法。如果您只有两个imageview,您也可以尝试在该imageview的顶部设置两个自定义透明按钮,因此您可以根据您为按钮提供的标签轻松知道触摸了哪个图像。

使用UITouch类方法ds您将获得触动的图像视图,或者您可以将imageview置于按钮内部,然后您将获得单击事件。

通过使用UITouch类方法,您将获得触动的图像视图,或者您可以将imageview置于按钮内部,然后您将获得单击事件。

您还可以创建两个按钮(而不是UIImageView)它们应该显示大致相同的图像(你甚至可以禁用触摸状态等),并且你可以免费获得UIResponder事件(如;你可以将操作指向选择器)

更新:这里大致介绍了如何配置按钮(尽管没有配置按钮)

触摸按钮时,您的按钮将转到以下方法:

- (void)buttonTouched:(id)sender
{
   // .. add your stuff to your database .. //
   // .. you can identify your button by sender, or give the button a tag (number) to identify it .. /
}

您还可以创建两个具有图像的按钮(而不是UIImageView)。它们的显示应该大致相同(您甚至可以禁用触摸状态等)。并且您可以免费获得UIResponder事件(如;您可以将操作定向到选择器)

更新:这里大致介绍了如何配置按钮(尽管没有配置按钮)

触摸按钮时,您的按钮将转到以下方法:

- (void)buttonTouched:(id)sender
{
   // .. add your stuff to your database .. //
   // .. you can identify your button by sender, or give the button a tag (number) to identify it .. /
}


您可以使用触摸方法来实现这一点。使用触摸方法,您将获得触摸的图像视图。选择后,从图像视图中获取图像,并将图像数据转储到文件而不是数据库中。实际上,我无法正确地获取您。请您详细解释我。谢谢您可以使用触摸方法来实现这一点将获取所接触的图像视图..并在选择后从图像视图获取图像并将图像数据转储到文件而不是数据库中。实际上,我无法正确获取您的图像,请您详细解释我。谢谢,但如何将所选按钮的值保存到sqlite数据库中。请您在这方面帮助我。根据按钮,您可以保存图像But如何在sqlite数据库中保存所选按钮的值。您可以在这方面帮助我吗。根据按钮,您可以保存图像。您是正确的,但我想在数据库中保存我的值。在sqlite数据库中,布尔值不能绑定。感谢您现在不可以将您的值保存在nsstring中,或者根据您的布尔条件(如如果布尔值为“是”,则取两个整数并传递1;如果布尔值为“否”,则传递0。否现在可以将值保存在nsstring中,或者根据布尔值条件(例如,如果布尔值为“是”,则取两个整数并传递1;如果布尔值为“否”,则传递0)。您是正确的,但我想将值保存在数据库中。在sqlite数据库中,布尔值无法绑定。谢谢否现在可以将您的值保存在nsstring中,或者根据您的布尔条件(例如,如果布尔值为是,则取两个整数并传递1;如果布尔值为否,则传递0)保存您的值。否现在可以将您的值保存在nsstring中,或者根据您的布尔条件(例如,如果布尔值为是,则获取两个整数并传递1;如果布尔值为否,则传递0)。嗨,我有一个doubt first image和secImage是图像视图或图像对象。我怀疑first image和secImage是图像视图或图像对象