在tableview中添加便捷按鈕

來源:互聯網
上載者:User

在tableview中添加便捷按鈕


“頂部”、“中間”、“底部”

- (void)viewDidLoad

{

    //******************************************//

    

    //=================設定工具條增加三個快速上移、快速移動到中間、快速下移按鈕=========================//

    static const NSInteger dudaoBarButtonWidth = 90;

    //工具條按鈕

    UIBarButtonItem* topBarButton = [ [ [ UIBarButtonItem alloc ] 

                                       initWithTitle: @"頂部"

                                       style: UIBarButtonItemStyleBordered

                                       target: self

                                       action: @selector(topButtonDidPush) ] autorelease ]; 

    

    UIBarButtonItem* buttomBarButton = [ [ [ UIBarButtonItem alloc ]

                                          initWithTitle:@"底部" 

                                          style: UIBarButtonItemStyleBordered 

                                          target: self

                                          action: @selector(buttomBarButtonDidPush ) ] autorelease ];

    

    UIBarButtonItem* middleBarButton = [ [ [ UIBarButtonItem alloc ]

                                          initWithTitle:@"中間" 

                                          style: UIBarButtonItemStyleBordered 

                                          target: self

                                          action: @selector(middleBarButtonDidPush ) ] autorelease ];

    UIBarButtonItem* spaceBarButton1 = [ [ [ UIBarButtonItem alloc ] 

                                          initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace

                                          target: nil 

                                          action: nil ] autorelease ];

    

    UIBarButtonItem* spaceBarButton2 = [ [ [ UIBarButtonItem alloc ] 

                                          initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace

                                          target: nil

                                          action: nil ] autorelease ];

    spaceBarButton1.width = 10;

    spaceBarButton2.width = 10;

    topBarButton.width = dudaoBarButtonWidth;

    middleBarButton.width = dudaoBarButtonWidth;

    buttomBarButton.width = dudaoBarButtonWidth;

    

    [ self setToolbarItems: [ NSArray arrayWithObjects: topBarButton , spaceBarButton1 , middleBarButton , spaceBarButton2 , buttomBarButton , nil ] ];

    

//=====================設定工具條增加兩個快速上移、快速下移按鈕==================================//

}

- (void)topButtonDidPush

{

    //滾動到第一個儲存格

    NSIndexPath* indexPath = [ NSIndexPath indexPathForRow: 0  inSection: 0 ];

    [ self.tableView scrollToRowAtIndexPath: indexPath

                           atScrollPosition: UITableViewScrollPositionNone animated: YES ];

}

- (void)middleBarButtonDidPush

{

    //滾動到中間單元

    id key = [ dateMutableArray_ objectAtIndex: (NSInteger)  ( [ dateMutableArray_ count ] - 1  ) / 2 ];

    

    NSIndexPath* indexPath = [ NSIndexPath indexPathForRow:  [ [ arrangeMutableDictionary_ objectForKey: key ] count ] - 1 inSection: (NSInteger)  ( [ dateMutableArray_ count ] - 1  ) / 2 ];

    

    [ self.tableView scrollToRowAtIndexPath: indexPath atScrollPosition: UITableViewScrollPositionNone animated: YES ];

}

- (void)buttomBarButtonDidPush

{

    //滾動到最後一個儲存格

    id key = [ dateMutableArray_ objectAtIndex:  [ dateMutableArray_ count ] - 1  ];

    

    NSIndexPath* indexPath = [ NSIndexPath indexPathForRow: [ [ arrangeMutableDictionary_ objectForKey: key ] count ] - 1 inSection: [ dateMutableArray_ count ] - 1 ];

    [ self.tableView scrollToRowAtIndexPath: indexPath atScrollPosition: UITableViewScrollPositionNone animated: YES ];

}

//=======================================================================================//

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.