如何在不单击按钮的情况下运行UI按钮的功能

时间:2017-05-26 05:26:38

标签: objective-c uibutton action

这是我的代码:

-(void)btnSelectItem:(id)sender{

    NSString *userId =[[NSUserDefaults standardUserDefaults] valueForKey:USER_ID_KEY];
    [sender setBackgroundImage:[UIImage imageNamed:@"radio_selected"] forState:UIControlStateNormal];
    int i = (int)[sender tag];
    //[CollectionViewSize performBatchUpdates:^{ [CollectionViewSize reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]]; } completion:nil];



   // [CollectionViewSize reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i section:0]]];

    strMenuID = [NSString stringWithFormat:@"%@",[[arayResponce objectAtIndex:i]valueForKey:@"menu_id"]];
    lblItemCount.text = [NSString stringWithFormat:@"%@",[[arayResponce objectAtIndex:i]valueForKey:@"price"]];
    [adCartParam removeAllObjects];

    adCartParam = [NSMutableDictionary dictionary];
    [adCartParam setObject:[NSNumber numberWithInt:kresto_id] forKey:@"resto_id"];
    [adCartParam setObject:strMenuID forKey:@"menu_id"];
    [adCartParam setObject:userId forKey:@"cust_id"];
    [adCartParam setObject:[AppDelegate getDelegate].subCategoryID forKey:@"cat_id"];

    NSString  *price = [CommonClass stringByReplacing:lblItemCount.text and:@"$" withString:@""];

    ///[lblItemCount.text stringByReplacingOccurrencesOfString:@"$"
                                                                    // withString:@""];
    [adCartParam setObject:price forKey:@"price"];

    [adCartParam setObject:@1 forKey:@"qty"];
    [adCartParam setObject:[[arayResponce objectAtIndex:i]valueForKey:@"size_id"] forKey:@"size_id"];



}

3 个答案:

答案 0 :(得分:0)

 //if you need the highlight   
 [button setHighlighted:YES];
 [button sendActionsForControlEvents:UIControlEventTouchUpInside];

答案 1 :(得分:0)

[self btnSelectItem:yourButton];

答案 2 :(得分:0)

首先您使用-(void)btnSelectItem:(id)sender更改-(void)btnSelectItem:(UIButton*)sender 然后从任何方法调用它。与[self btnSelectItem:yourButtonOutlet]