Добавьте панель инструментов на UITableViewController

Решением TK является то, которое Вы обычно использовали бы для этого вида вещи.

Для частичного сценария освещения, у Вас мог быть он так, чтобы, если мозаика приводит к тому, чтобы быть в тени, та мозаика была тогда разделена на 4 мозаики, и каждый из тех тестируется. Вы могли тогда разделить это так, как Вы хотели?

Редактирование:

можно также оптимизировать его немного, не тестируя ни одной из мозаик, смежных со светом - это было бы более важно сделать, когда у Вас есть несколько источников света, я предполагаю...

37
задан PeyloW 29 September 2009 в 14:35
поделиться

3 ответа

Никаких проблем, UITableViewController является подклассом UIViewController . Так получилось, что в iPhone OS 3.0 любой UIViewController (и подклассы) может работать вместе с UINavigationController для обеспечения контекстно-зависимой панели инструментов.

чтобы это работало, вы должны:

  • Убедитесь, что вы используете UINavigationController , чтобы содержать все ваши контроллеры представления, которым нужна панель инструментов.
  • Установите свойство toolbarsItems контроллера представления которому нужна панель инструментов.

Это почти так же просто, как установить контроллер представления ' s название, и должно быть сделано таким же образом. Скорее всего, переопределив инициализатор initWithNibName: bundle: . В качестве примера:

-(id)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle;
{
  self = [super initWithNibName:name bundle:bundle];
  if (self) {
    self.title = @"My Title";
    NSArray* toolbarItems = [NSArray arrayWithObjects:
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                      target:self
                                                      action:@selector(addStuff:)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch 
                                                      target:self
                                                      action:@selector(searchStuff:)],
        nil];
    [toolbarItems makeObjectsPerformSelector:@selector(release)];
    self.toolbarItems = toolbarItems;
    self.navigationController.toolbarHidden = NO;
  }
  return self;
}

Вы также можете использовать setToolbarItems: animated: вместо назначения свойству toolbarItems , чтобы добавлять и удалять элементы панели инструментов в анимированной форме на лету.

51
ответ дан 27 November 2019 в 04:14
поделиться
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    //Initialize the toolbar
    toolbar = [[UIToolbar alloc] init];
    toolbar.barStyle = UIBarStyleDefault;

    //Set the toolbar to fit the width of the app.
    [toolbar sizeToFit];

    //Caclulate the height of the toolbar
    CGFloat toolbarHeight = [toolbar frame].size.height;

    //Get the bounds of the parent view
    CGRect rootViewBounds = self.parentViewController.view.bounds;

    //Get the height of the parent view.
    CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);

    //Get the width of the parent view,
    CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);

    //Create a rectangle for the toolbar
    CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);

    //Reposition and resize the receiver
    [toolbar setFrame:rectArea];

    //Create a button
    UIBarButtonItem *infoButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)];

    [toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];

    //Add the toolbar as a subview to the navigation controller.
    [self.navigationController.view addSubview:toolbar];



[[self tableView] reloadData];

}

- (void) info_clicked:(id)sender {


 [self.navigationController popViewControllerAnimated:YES];
    [toolbar removeFromSuperview];

    }

А в Swift 3:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    //Initialize the toolbar
    let toolbar = UIToolbar()
    toolbar.barStyle = UIBarStyle.default

    //Set the toolbar to fit the width of the app.
    toolbar.sizeToFit()

    //Caclulate the height of the toolbar
    let toolbarHeight = toolbar.frame.size.height

    //Get the bounds of the parent view
    let rootViewBounds = self.parent?.view.bounds

    //Get the height of the parent view.
    let rootViewHeight = rootViewBounds?.height

    //Get the width of the parent view,
    let rootViewWidth = rootViewBounds?.width

    //Create a rectangle for the toolbar
    let rectArea = CGRect(x: 0, y: rootViewHeight! - toolbarHeight, width: rootViewWidth!, height: toolbarHeight)

    //Reposition and resize the receiver
    toolbar.frame = rectArea

    //Create a button
    let infoButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: #selector(infoClicked))

    toolbar.items = [infoButton]

    //Add the toolbar as a subview to the navigation controller.
    self.navigationController?.view.addSubview(toolbar)
}

func infoClicked() {
    //Handle Click Here
}
13
ответ дан 27 November 2019 в 04:14
поделиться

Чтобы рецепт PeyloW работал, мне нужно было добавить следующую дополнительную строку кода:

self.navigationController.toolbarHidden = NO;

Надеюсь, что это поможет ...

40
ответ дан 27 November 2019 в 04:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: