показать другое представление с другим количеством нажатий от UIBarButtonItem - PullRequest
0 голосов
/ 14 декабря 2010

Я читал об UITouch и UIGestureRecognizer, но я все еще очень запутался, в чем разница между ними. У меня есть один случай. В моем приложении у меня есть barbuttonitem, я хочу показать другой вид, когда нажмите эту кнопку. если я делаю одиночную вкладку, я хочу показать текстовое представление, но когда я делаю одиночную вкладку снова, я хочу показать всплывающее окно от этой кнопки. Кто-нибудь может дать мне пример кода, чтобы сделать это и дать небольшое объяснение того, в чем разница между UITouch и UIGestureRecognizer ???

UPDATE

barbuttonitem - это обертка UISegmentedControl, вот картинка из дизайна alt text

я пытался использовать touchesBegan: withEvent: и touchesEnded: withEvent: для решения этой проблемы, но я не знаю, как подключить его к этому barbuttonitem. Это код, который я сделал:

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

}



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];
*

} * 1013

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

}

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

}

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

fileProperties.docProperties = _docsegmentmodels;
fileProperties.index = _docSegmentedControl.selectedSegmentIndex; //index utk nilai2 di textfield
[self.filePropertiesPopover presentPopoverFromBarButtonItem:sender 
                                   permittedArrowDirections:UIPopoverArrowDirectionUp
                                                   animated:YES];
* *} Тысяча двадцать-один
- (IBAction)docSegmentAction:(id)sender{
NSLog(@"open file");
isFileOpen = YES;
[self.moreFilePopOverController dismissPopoverAnimated:YES];
[self.filePropertiesPopover dismissPopoverAnimated:YES];

[self showTextView];

}

есть ли какая-то ошибка в моем понимании?

1 Ответ

0 голосов
/ 14 декабря 2010

В вашем случае вам не нужен UIGestureRecognizer. Просто установите действие barbuttonitem для метода, который должен вызываться при нажатии кнопки. Пусть метод отслеживает состояние просмотра текста и в зависимости от него показывает его или показывает всплывающее окно.

...