English 中文(简体)
显示不同观点,从国际商品调查(Wrap an UISegmentedControl)中得出不同主次。
原标题:show different view with different tap count from UIBarButtonItem (wrap an UISegmentedControl)

i have read about UITouch and UIGestureRecognizer, but i still really confused what the difference between them. I have one case. In my app, i have a barbuttonitem, i want to show different view when a tap that button. if i do a singletap, i want to show a textview, but when i do a singletap again, i want to show a popover from that button. is there somebody can give me an example code to do it and give a little explanation about what is the difference between UITouch and UIGestureRecognizer???

<>>>>>

the barbuttonitem is a wrapper of UISegmentedControl, here s a pic from the desain alt text

i was try to use touchesBegan:withEvent: and touchesEnded:withEvent: to solve this problem, but i dont know how to connect it to that barbuttonitem. This is the code i made :

-(void)addSegment{


NSAutoreleasePool *pool;
int count_doc = [_docsegmentmodels count];
NSLog(@"count doc add segment : %d", count_doc);
pool = [[NSAutoreleasePool alloc] init];
DocSegmentedModel *sl;
NSMutableArray *segmentTextMutable = [NSMutableArray array];

for(int i=0 ;(i<count_doc && i < max_segment);i++){
    sl = [_docsegmentmodels objectAtIndex:i];
    NSString *evalString = [[KoderAppDelegate sharedAppDelegate] setStringWithLength:sl.docSegmentFileName:10];  
    [segmentTextMutable addObject:NSLocalizedString(evalString,@"")];

iii



NSArray *segmentText = [segmentTextMutable copy];

_docSegmentedControl = [[UISegmentedControl alloc] initWithItems:segmentText];
_docSegmentedControl.selectedSegmentIndex = 0; 
_docSegmentedControl.autoresizingMask =  UIViewAutoresizingFlexibleHeight;
_docSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled;//UISegmentedControlStylePlain;// UISegmentedControlStyleBar;//UISegmentedControlStyleBezeled;
//docSegmentedControl.frame = CGRectMake(0, 0, 800, 46.0);
[_docSegmentedControl addTarget:self action:@selector(docSegmentAction:) forControlEvents:UIControlEventValueChanged];

// Add the control to the navigation bar
//UIBarButtonItem *segmentItem = [[UIBarButtonItem alloc] initWithCustomView:_docSegmentedControl];
segmentItem = [[UIBarButtonItem alloc] initWithCustomView:_docSegmentedControl];
self.navItem.leftBarButtonItem = segmentItem;
self.navItem.leftBarButtonItem.title = @"";


[pool release];
[segmentItem release];
[_docSegmentedControl release];

iii

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[NSObject cancelPreviousPerformRequestsWithTarget:self 
                                         selector:@selector(segmentItemTapped:) object:segmentItem];

iii

-(void)touchesEnd:(NSSet *)touches withEvent:(UIEvent *)event{
if (touches.count == 1) {
    if (theTouch.tapCount == 2) {
        [self performSelector:@selector(segmentItemTapped:)withObject:segmentItem afterDelay:0.35];
    iiielse {
        [self performSelector:@selector(docSegmentAction:) withObject:segmentItem afterDelay:0.0];
    iii
iii   

iii

- (IBAction)segmentItemTapped:(id)sender{  

if (self.fileProperties == nil) {
    self.fileProperties = [[[FilePropertiesViewController alloc] initWithNibName:@"FilePropertiesViewController" bundle:nil]autorelease];
    fileProperties.delegate = self;
    self.filePropertiesPopover = [[[UIPopoverController alloc] initWithContentViewController:fileProperties]autorelease];
    [_docsegmentmodels objectAtIndex:_docSegmentedControl.selectedSegmentIndex];
iii

fileProperties.docProperties = _docsegmentmodels;
fileProperties.index = _docSegmentedControl.selectedSegmentIndex; //index utk nilai2 di textfield
[self.filePropertiesPopover presentPopoverFromBarButtonItem:sender 
                                   permittedArrowDirections:UIPopoverArrowDirectionUp
                                                   animated:YES];

iii

- (IBAction)docSegmentAction:(id)sender{
NSLog(@"open file");
isFileOpen = YES;
[self.moreFilePopOverController dismissPopoverAnimated:YES];
[self.filePropertiesPopover dismissPopoverAnimated:YES];

[self showTextView];

iii

我的理解中是否有任何错误?

问题回答

In your case you don t need UIGestureRecognizer. Simply set the action of the barbuttonitem to the method that should be called when the button is tapped. Have the method keep track of the state of the textview and depending on it show it or show the popover.





相关问题
tap detecting garbage value

I m using Apple TapDetectingImageView class from Autoscroll example. Static analizer shows the following warning: Classes/TapDetectingImageView.m:68:30:{68:17-68:29}: warning: The left operand of ...

Double Tap for certain part of view

I am bit stacked with a functionality that should perform a certain task after double taping on a certain place on UIView. I know how to count number of taps, but do not know how to determinate which ...

jQtouch tap and link problem

I m having a problem with jQtouch when using tap on links, I m trying to get a link to change background color when tapped a la iphone appstore (the blue color) so I m using this code : <script&...

Making images appear... How?

Could someone please tell me how to make an image appear when the user taps the screen and make it appear at the position of the tap. Thanks in advance, Tate

iPhone + detect tap of disabled UIControl

I am developing In App purchase for one existing application. Scenario is something like I have a feature in application (which contain UITextField control), which is initially disabled and when user ...

OpenVPN TAP Driver Installation

I m trying to control multiple instances of OpenVPN s TAP driver in windows via tapinstall. It seems that because all of the devices have the same HWID -- tap0901 -- I m unable to remove any single ...

热门标签