2017-05-26 152 views
0

这里运行的UIButton的功能是我的代码:我怎么可以不点击按钮

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



} 
+1

你可以用'[button sendActionsForControlEvents:UIControlEventTouchUpInside];' –

+0

在viewdidload中调用这个btnSelectItem方法。 –

回答

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

[自btnSelectItem:yourButton]。

0

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