2010-07-03 2 views
3

Я создаю приложение для iPad, и я хочу показать UIPopoverController со стрелкой, указывающей на кнопку раскрытия подробностей для строки, к которой она принадлежит. Я хочу сделать это в методе tableView:accessoryButtonTappedForRowWithIndexPath:. В настоящее время я это, с фиктивным CGRect:Показать UIPopoverController из кнопки раскрытия подробностей в UITableViewCell

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 
    // Dismiss in the case it shows itself somewhere else 
    [addFeedPopup dismissPopoverAnimated:YES]; 

    // Set up 
    TNSubscribeToFeedController *subscribeToFeedController = [[TNSubscribeToFeedController alloc] initWithNibName:@"SubscribeToFeed" bundle:nil]; 
    UINavigationController *subscribeToFeedNavigationController = [[UINavigationController alloc] initWithRootViewController:subscribeToFeedController]; 
    subscribeToFeedController.title = @"Subscribe to feed"; 
    subscribeToFeedController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:nil]; 
    subscribeToFeedController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:nil]; 
    /* 
    * Note that we use the UINavigationController pure for the nices UINavigationBar. 
    */ 

    // Show in popup 
    addFeedPopup = [[UIPopoverController alloc] initWithContentViewController:subscribeToFeedNavigationController]; 
    addFeedPopup.popoverContentSize = CGSizeMake(480, 320); 
    [addFeedPopup presentPopoverFromRect:CGRectMake(0, 0, 20, 20) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 

    // Memory 
    [subscribeToFeedNavigationController release]; 
    [subscribeToFeedController release]; 
} 

Кроме того, когда UITableView находится в режиме редактирования, кнопка раскрытия детали составляет около 60 пикселей влево, так как я использовать это, чтобы настроить мои строки:

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SectionTwoCell"] autorelease]; 
} 
cell.textLabel.text = [NSString stringWithFormat:@"Feed %d", indexPath.row]; 
cell.detailTextLabel.text = @"Description"; 
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
cell.editingAccessoryType = cell.accessoryType; 
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^// 
//  TWO LINES BACK DEAR SO USER  // 

Может ли кто-нибудь помочь мне с этой проблемой? Благодарю.


О, и это также можно отключить скроллинг и отключить выбрав что-нибудь, пока UIPopoverController закрыт (перфекционизм)?

ответ

9

Чтобы сделать то, что вы хотите, вам нужен аксессуарПросмотр и установка аксессуарНастройки не создается. Однако он будет работать, если вы создадите кнопку и установите ее как cell.accessoryView.

Создать и установить accessoryView, когда создается клетка:

... 
    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [disclosureButton addTarget:self action:@selector(discloseDetails:) forControlEvents:UIControlEventTouchUpInside]; 
    cell.accessoryView = disclosureButton; 
    ... 

Replace Tableview: accessoryButtonTappedForRowWithIndexPath: с discloseDetails :. Это выглядит так же, как то, что у вас есть, прежде чем это я только положить изменения ниже:

- (void) discloseDetails:(UIButton *)sender { 
    ... 
    UITableViewCell *cell = (UITableViewCell *) sender.superview; 
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; // if needed 
    [addFeedPopup presentPopoverFromRect:cell.accessoryView.bounds inView:cell.accessoryView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 
    ... 
} 

Если вы не нуждаетесь в клетку, это можно сделать еще проще:

- (void) discloseDetails:(UIButton *)sender { 
    ... 
    [addFeedPopup presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 
    ... 
} 

Вот что это выглядит как

enter image description here

Смежные вопросы