Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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
Ios 单击单元格中的可单击图像视图和按钮视图(UITableView或collectionView)_Ios_Objective C_Uitableview_Ipad_Collectionview - Fatal编程技术网

Ios 单击单元格中的可单击图像视图和按钮视图(UITableView或collectionView)

Ios 单击单元格中的可单击图像视图和按钮视图(UITableView或collectionView),ios,objective-c,uitableview,ipad,collectionview,Ios,Objective C,Uitableview,Ipad,Collectionview,我有一个关于ios objective-c的UI设计问题。在一个页面中需要显示数千个产品图像,每行5个产品,每个图像下每个产品有2行信息。如果用户单击产品图像,我需要将其添加到购物车。此外,我需要在每个产品图像下添加一个小按钮。如果用户单击该按钮,我将显示一个窗口,允许用户为该产品编写注释 如何设计这种用户界面?谢谢。在cellForRowAtIndexPath中: ip是indepath cell.btn.tag = ip.row; [cell.btn addTarget:self actio

我有一个关于ios objective-c的UI设计问题。在一个页面中需要显示数千个产品图像,每行5个产品,每个图像下每个产品有2行信息。如果用户单击产品图像,我需要将其添加到购物车。此外,我需要在每个产品图像下添加一个小按钮。如果用户单击该按钮,我将显示一个窗口,允许用户为该产品编写注释


如何设计这种用户界面?谢谢。

在cellForRowAtIndexPath中: ip是
indepath

cell.btn.tag = ip.row;
[cell.btn addTarget:self action:@selector(btnclk:) forControlEvents:UIControlEventTouchUpInside];
转到查看控制器并添加此功能,该功能将在每次调用任何按钮时调用。。。每个按钮都有唯一的标签(因为原始编号),所以您可以通过其编号为每个按钮设置条件

-(void)btnclk:(UIButto*)sender
{
     if (sender.tag == 0) 
      // btn clicked from cell number 0
}

我是从iPhone上写的,因此当我使用PC时,我会在cellForRowAtIndexPath中写更多内容。

cell.yourImageView.tag = ip.row;
cell.youreImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
// this maybe repeat to addGesture
// you can user custom UITableViewCell to avoid it
[cell.youreImageView addGestureRecognizer:tap];


- (void)tapClick:(id)sender
{
    UITapGestureRecognizer *tap = sender;
    UIView *view = tap.view;
    if (view.tag == 0) {
        // row 1
    }
}
ip是
indepath

cell.btn.tag = ip.row;
[cell.btn addTarget:self action:@selector(btnclk:) forControlEvents:UIControlEventTouchUpInside];
转到查看控制器并添加此功能,该功能将在每次调用任何按钮时调用。。。每个按钮都有唯一的标签(因为原始编号),所以您可以通过其编号为每个按钮设置条件

-(void)btnclk:(UIButto*)sender
{
     if (sender.tag == 0) 
      // btn clicked from cell number 0
}
我是从iPhone上写的,因此当我使用PC时,我会写更多的内容。

以下是代码:

cell.yourImageView.tag = ip.row;
cell.youreImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
// this maybe repeat to addGesture
// you can user custom UITableViewCell to avoid it
[cell.youreImageView addGestureRecognizer:tap];


- (void)tapClick:(id)sender
{
    UITapGestureRecognizer *tap = sender;
    UIView *view = tap.view;
    if (view.tag == 0) {
        // row 1
    }
}
UIButton*btnLink;//create button

btnLink=[[UIButton alloc]initWithFrame:CGRectMake(8, 8, self.view.frame.size.width, 77)];//set frame

[btnLink setTitle:[@"yourTitle" forState:UIControlStateNormal];

btnLink.tag = indexPath.row;//set tag 

[btnLink addTarget:self action:@selector(linkClick:) forControlEvents:UIControlEventTouchUpInside];//set action

[cell addSubview:btnLink];



-(IBAction)linkClick:(id)sender{

UIButton *btnSender = sender;

NSLog(@"btnSender.tag====>%ld",(long)btnSender.tag);//check your clicked button tag number

NSDictionary *dS;

dS= [yourArray objectAtIndex:btnSender.tag];

NSString*myurl=[dS objectForKey:@"link"];

NSURL *url = [NSURL URLWithString:@"yourURL OR ANYTHING"];
[[UIApplication sharedApplication] openURL:url];
代码如下:

UIButton*btnLink;//create button

btnLink=[[UIButton alloc]initWithFrame:CGRectMake(8, 8, self.view.frame.size.width, 77)];//set frame

[btnLink setTitle:[@"yourTitle" forState:UIControlStateNormal];

btnLink.tag = indexPath.row;//set tag 

[btnLink addTarget:self action:@selector(linkClick:) forControlEvents:UIControlEventTouchUpInside];//set action

[cell addSubview:btnLink];



-(IBAction)linkClick:(id)sender{

UIButton *btnSender = sender;

NSLog(@"btnSender.tag====>%ld",(long)btnSender.tag);//check your clicked button tag number

NSDictionary *dS;

dS= [yourArray objectAtIndex:btnSender.tag];

NSString*myurl=[dS objectForKey:@"link"];

NSURL *url = [NSURL URLWithString:@"yourURL OR ANYTHING"];
[[UIApplication sharedApplication] openURL:url];

只需将按钮添加为子视图,这就是你的意思?如何知道单击了哪个按钮和哪个图像?Swift或OBJECT?你理解我的答案吗?只需将按钮添加为子视图,这就是你的意思?如何知道单击了哪个按钮和哪个图像?Swift或OBJECT?你理解我的答案吗?