在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 ];
}
//=======================================================================================//