从集合视图中的按钮发送操作

时间:2014-01-27 20:51:41

标签: ios button uicollectionview pushviewcontroller

我有一个查询,它会拉出最近的10个对象,并在集合视图的按钮中显示每个对象的标题。我要做的是有一个操作,打开一个新的视图控制器,显示从集合视图中选择的对象的信息。我需要帮助的是在按钮操作中连接所选对象。我是Xcode的新手,可以使用一些建议。这是定义查询的代码:

int i = 0;
        for (PFObject *object in objects) {
            if (i >= [self.EventTitles count]) break;//to make sure we only write up to the max number of UILabels available in EventTitles
            [(UIButton *)self.EventButtons[i] setTitle:[object objectForKey:@"name"] forState:UIControlStateNormal];
            [(UIButton *)self.EventButtons[i] addTarget:self action:(social:) forControlEvents:UIControlEventTouchUpInside];
            i++;
                        }

然后是带有动作的代码

- (IBAction)social:(id)sender{

    UIActionSheet *share = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Close" destructiveButtonTitle:nil otherButtonTitles:@"Call",@"Directions",@"Website",@"Checkin", nil];

    [share showInView:self.view];
}


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    //Each button title we gave to our action sheet is given a tag starting with 0.
    if (buttonIndex == 0) {
        NSString* yourActualNumber = [NSString stringWithFormat:@"tel:%@",????????];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:yourActualNumber]];
        NSLog(@"phone");
        //Check Twitter accessibility and at least one account is setup.

    }

我只是不知道如何将对象连接到动作,然后在新视图控制器上显示该信息。

更新:我使用查询中的新行更新了代码,但是它无法声明操作社交是未声明的,但它是?我还更改了操作以执行操作表而不是新的视图控制器。我现在需要的是从对象到动作的连接以及如何在动作表函数中适当地写入对象中的键。

2 个答案:

答案 0 :(得分:0)

  

我需要帮助的是连接按钮中的所选对象   动作。

[button addTarget:self action:@selector(DetailEvent1 :) forControlEvents:UIControlEventTouchUpInside]

  

然后在新视图控制器上显示该信息。

我真的不知道你在这里问的是什么,如果你澄清我会尽力帮助:)

答案 1 :(得分:0)

以下是选择项目时显示操作表的示例。我只是使用所选项目的索引路径,但我假设您需要保存其他一些数据,因此Action Sheet委托可以使用它。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSString *str = [NSString stringWithFormat:@"Call number %d", indexPath.row];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:(id < UIActionSheetDelegate >)self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:str, nil];

    [actionSheet showInView:self.view];
}
相关问题