开发者

How to count and display user taps in the bar button item?

开发者 https://www.devze.com 2023-02-25 00:21 出处:网络
I am developing a project in which the user can add the object to favorite list that is table View. here I adding the object through rightBarBu开发者_运维知识库ttonItem. I wanna show a message if User

I am developing a project in which the user can add the object to favorite list that is table View. here I adding the object through rightBarBu开发者_运维知识库ttonItem. I wanna show a message if User tap the right BarButton more than one. message is nothing but a UILabel that contains text like "Object already exist". please help me to solve this problem. thanks....


You might have a method that is executed when the button is tapped where you add the item to your table view. Lets say the method is called didClickButton. Have a Bool variable say isItemAdded indicating the status of the item. Set it to NO initially. when button is pressed check if its NO. If NO then proceed and set it to YES else display "Alert already added"

-(void)didClickButton
{
if(!isItemAdded)
{
//code to add to tableview
isItemAdded = YES;
}
else
{
//code to show message or alert
}
}


Initiaize a global counter and use it to count the taps by incrimienting it inside the method that is called by your rightBarButtonItem.

int tapsCtr =  0; 

Put this code inside your method:

tapsCtr++; 
if(tapsCtr > 1){
      NSLog(@"User tapped more than once"); 
      tapsCtr = 0;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消