一个view上的两个按钮有两个tableview的来回切换功能等,用了auto layout
2016-09-16 12:29
465 查看
#import "MyPhraseTabViewController.h"
#import "Categories.h"
#import "GlossaryTableViewCell.h"
#import "MBProgressHUD+LJ.h"
#import "PhraseDisplayCell.h"
#import "UIView+Toast.h"
#import "MecTraPreferenceManager.h"
typedef NS_ENUM(NSInteger, TabButtonTag)
{
TabButtonTagMyPhrase = 1,
//<! マイフレーズ
TabButtonTagHistory, //<!
日本語履歴
};
@interface
MyPhraseTabViewController () <UITableViewDataSource,UITableViewDelegate>
{
TabButtonTag selectedTab_;
//<! 選択中のタブ
}
@property (nonatomic,assign)CGSize
greetSize;
@property (nonatomic,strong)NSMutableArray
*myphrase;
@property (nonatomic,strong)NSMutableArray
*history;
@property (nonatomic,strong)NSMutableArray
*plusbts;
@property (nonatomic,
weak) IBOutlet
UIButton *buttonMyPhrase;
//<! マイフレーズボタン
@property (nonatomic,
weak) IBOutlet
UIButton *buttonHistory;
//<! 履歴ボタン
@property (nonatomic,
weak) IBOutlet
UIView *lineView;
//<! 仕切り線
@property (nonatomic,
weak) IBOutlet
UITableView *phraseTableView;
//<! フレーズ表示テーブル
@property (nonatomic,
strong) UIImage *plusButtonImageNormal;
@property (nonatomic,
strong) UIImage *plusButtonImageHighlighted;
@end
@implementation MyPhraseTabViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
self.view.backgroundColor = [UIColor
whiteColor];
// buttons
self.buttonMyPhrase.tag
= TabButtonTagMyPhrase;
self.buttonHistory.tag
= TabButtonTagHistory;
self.buttonMyPhrase.exclusiveTouch
=
self.buttonHistory.exclusiveTouch
= YES;
// デフォルトはマイフレーズ表示
[self
changeButtonWithSelectedButtonTag:TabButtonTagMyPhrase];
// line
self.lineView.backgroundColor
= [UIColor
customColorWithRed:105
green:204
blue:204];
// table
self.phraseTableView.dataSource
= self;
self.phraseTableView.delegate
= self;
self.phraseTableView.separatorStyle
= UITableViewCellSeparatorStyleNone;
// cell
[self.phraseTableView
registerNib:[UINib
nibWithNibName:NSStringFromClass([PhraseDisplayCell
class]) bundle:[NSBundle
mainBundle]]
forCellReuseIdentifier:PhraseDisplayCellID];
self.plusButtonImageNormal = [UIImage
imageNamed:@"bt_14_02"];
self.plusButtonImageHighlighted = [UIImage
imageNamed:@"bt_14_02_p"];
//データを取ります
TranslationDataManager *tdm = [TranslationDataManager
sharedInstance];
//日本語履歴
NSArray *historyList = [tdm
getJaHistoryList];
for (int i =
0;i < historyList.count;i++) {
[self.history
addObject:historyList[i]];
}
// マイフレーズ
NSArray *myPhraseList = (NSArray*)[tdm
getMyPhraseList];
for (int i =
0; i < myPhraseList.count;i++){
[self.myphrase
addObject:myPhraseList[i]];
}
// 長押しアクション
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer
alloc] initWithTarget:self
action:@selector(longPressGestureRecognized:)];
[self.phraseTableView
addGestureRecognizer:longPress];
}
- (void) viewDidAppear:(BOOL)animated
{
[super
viewDidAppear:animated];
// //先頭表示のためリロード
// [self.phraseTableView reloadData];
}
- (void)viewWillDisappear:(BOOL)animated
{
// DBにマイフレーズを保存
[[TranslationDataManager
sharedInstance]
setMyPhraseList:(NSArray *)self.myphrase];
[super
viewWillDisappear:animated];
}
# pragma mark - button callbacks
- (void) tabButtonTapped:(id)sender
{
if(sender ==
self.buttonMyPhrase) {
[self
changeButtonWithSelectedButtonTag:TabButtonTagMyPhrase];
}
else
if(sender == self.buttonHistory) {
[self
changeButtonWithSelectedButtonTag:TabButtonTagHistory];
}
[self.phraseTableView
reloadData];
}
-(void)longPressGestureRecognized:(id)sender
{
if(selectedTab_ ==
TabButtonTagHistory) {
return;
}
UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender;
UIGestureRecognizerState state = longPress.state;
CGPoint location = [longPress
locationInView:self.phraseTableView];
NSIndexPath *indexPath = [self.phraseTableView
indexPathForRowAtPoint:location];
static
UIView *snapshot =
nil;
static
NSIndexPath *sourceIndexPath =
nil;
switch (state) {
//移動が始まります
case
UIGestureRecognizerStateBegan:
if (indexPath){
sourceIndexPath = indexPath;
GlossaryTableViewCell *cell3 = [self.phraseTableView
cellForRowAtIndexPath:indexPath];
snapshot = [self
customSnapshoFromView:cell3];
__block
CGPoint center = cell3.center;
snapshot.center = center;
snapshot.alpha =
0.9;
[self.phraseTableView
addSubview:snapshot];
[UIView
animateWithDuration:0.25
animations:^{
center.y = location.y;
snapshot.center = center;
snapshot.transform =
CGAffineTransformMakeScale(1.05,
1.05);
snapshot.alpha =
0.9;
cell3.hidden =
YES;
[self.phraseTableView
reloadData];
}];
}
break;
case
UIGestureRecognizerStateChanged:{
//移動中
CGPoint center = snapshot.center;
center.y = location.y;
snapshot.center = center;
if (indexPath && ![indexPath
isEqual:sourceIndexPath]){
[self.myphrase
exchangeObjectAtIndex:indexPath.row
withObjectAtIndex:sourceIndexPath.row];
[self.phraseTableView
moveRowAtIndexPath:sourceIndexPath
toIndexPath:indexPath];
sourceIndexPath = indexPath;
}
break;
}
default:{
//移動しました
GlossaryTableViewCell *cell4 = [self.phraseTableView
cellForRowAtIndexPath:sourceIndexPath];
cell4.alpha =
0.9;
[UIView
animateWithDuration:0.25
animations:^{
snapshot.center = cell4.center;
snapshot.transform =
CGAffineTransformIdentity;
snapshot.alpha =
0.9;
cell4.alpha =
1.0;
}completion:^(BOOL finished) {
cell4.hidden =
NO;
sourceIndexPath = nil;
[snapshot removeFromSuperview];
snapshot = nil;
}];
[self.phraseTableView
reloadData];
break;
}
}
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
LogDebug(@"numberofrow %zd", (selectedTab_
== TabButtonTagMyPhrase) ?
_myphrase.count :
_history.count);
return (selectedTab_ ==
TabButtonTagMyPhrase) ?
_myphrase.count :
_history.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
PhraseDisplayCell *cell = [tableView
dequeueReusableCellWithIdentifier:PhraseDisplayCellID];
cell.accessoryType =
UITableViewCellAccessoryNone;
cell.labelPhrase.textColor = [UIColor
customColorWithRed:102
green:102
blue:102];
cell.labelPhrase.font = [UIFont
MecTraFontOfSize:17.0];
cell.separatorView.backgroundColor = tableView.separatorColor;
if(selectedTab_ ==
TabButtonTagMyPhrase) {
// マイフレーズ表示
cell.labelPhrase.text =
self.myphrase[indexPath.row];
[cell setButtonHidden:YES];
}
else {
// 履歴表示
cell.labelPhrase.text =
self.history[indexPath.row];
[cell.buttonPlus
setImage:self.plusButtonImageNormal
forState:UIControlStateNormal];
[cell.buttonPlus
setImage:self.plusButtonImageHighlighted
forState:UIControlStateHighlighted];
[cell.buttonPlus
addTarget:self
action:@selector(addDataToMyPhrase:)
forControlEvents:UIControlEventTouchUpInside];
cell.buttonPlus.tag = indexPath.row;
[cell setButtonHidden:NO];
}
return cell;
}
- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath
*)indexPath
{
LogDebug(@"編集%@",
selectedTab_ ==
TabButtonTagMyPhrase ?
@"可能" :
@"不可");
return (selectedTab_ ==
TabButtonTagMyPhrase) ?
true : false;
}
# pragma mark - UITableView delegate methods
//tableview1の削除機能を追加する
-(NSArray <UITableViewRowAction *> *)tableView:(UITableView *)tableView
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedTab_ ==
TabButtonTagMyPhrase) {
UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@"削除"
handler:^(UITableViewRowAction * action,
NSIndexPath * indexPath) {
[self.myphrase
removeObjectAtIndex:indexPath.row];
[self.phraseTableView
deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.phraseTableView
reloadData];
}];
[[TranslationDataManager
sharedInstance]
deleteMyPhrase:_myphrase[indexPath.row]];
return
@[deleteRowAction];
}
else {
return
nil;
}
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return
44;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
_dataString = (selectedTab_ ==
TabButtonTagMyPhrase) ?
_myphrase[indexPath.row] :
_history[indexPath.row];
NSNotificationCenter *center = [NSNotificationCenter
defaultCenter];
[center postNotificationName:@"cesuo"
object:_dataString];
//翻訳中画面を表示する
MBProgressHUD.langCode =
@"ja";
[MBProgressHUD
showMessage:@""];
[self.navigationController
popToRootViewControllerAnimated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
}
# pragma mark - local methods
- (void) changeButtonWithSelectedButtonTag:(TabButtonTag)tag
{
if(tag ==
TabButtonTagMyPhrase) {
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"pt_13_01"]
forState:UIControlStateNormal];
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"pt_13_01"]
forState:UIControlStateHighlighted];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"bt_13_01"]
forState:UIControlStateNormal];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"bt_13_01_p"]
forState:UIControlStateHighlighted];
// target
[self.buttonMyPhrase
removeTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[self.buttonHistory
addTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
}
else {
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"bt_14_01"]
forState:UIControlStateNormal];
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"bt_14_01_p"]
forState:UIControlStateHighlighted];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"pt_14_01"]
forState:UIControlStateNormal];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"pt_14_01"]
forState:UIControlStateHighlighted];
// target
[self.buttonMyPhrase
addTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[self.buttonHistory
removeTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
}
selectedTab_ = tag;
}
-(UIView *)customSnapshoFromView:(UIView *)inputView
{
//inputviewにimageを作る
UIGraphicsBeginImageContextWithOptions(inputView.bounds.size,
NO,
0);
[inputView.layer
renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//image view
UIView *snapshot = [[UIImageView
alloc] initWithImage:image];
snapshot.layer.masksToBounds =
NO;
snapshot.layer.cornerRadius =
0.0;
snapshot.layer.shadowRadius =
5.0;
snapshot.layer.shadowOpacity =
1;
return snapshot;
}
- (void) addDataToMyPhrase:(UIButton *)button
{
//重複はさせない
for (int i=0;i<_myphrase.count;i++){
if ([_myphrase[i]
compare:_history[button.tag]] ==
NSOrderedSame) {
[self.view
makeToast:@"マイフレーズに登録済みです。"];
return;
}
}
[self.view
makeToast:@"マイフレーズに登録しました。"];
//履歴から追加
[_myphrase
addObject:_history[button.tag]];
[[TranslationDataManager
sharedInstance]
addMyPhrase:_history[button.tag]];
[self.phraseTableView
reloadData];
}
//deleteDataのインスタンスを作る
-(NSMutableArray *)myphrase
{
if (_myphrase ==
nil) {
_myphrase = [NSMutableArray
array];
}
return
_myphrase;
}
//deleteData3のインスタンスを作る
-(NSMutableArray *)history
{
if (_history ==
nil) {
_history = [NSMutableArray
array];
}
return
_history;
}
@end
#import "Categories.h"
#import "GlossaryTableViewCell.h"
#import "MBProgressHUD+LJ.h"
#import "PhraseDisplayCell.h"
#import "UIView+Toast.h"
#import "MecTraPreferenceManager.h"
typedef NS_ENUM(NSInteger, TabButtonTag)
{
TabButtonTagMyPhrase = 1,
//<! マイフレーズ
TabButtonTagHistory, //<!
日本語履歴
};
@interface
MyPhraseTabViewController () <UITableViewDataSource,UITableViewDelegate>
{
TabButtonTag selectedTab_;
//<! 選択中のタブ
}
@property (nonatomic,assign)CGSize
greetSize;
@property (nonatomic,strong)NSMutableArray
*myphrase;
@property (nonatomic,strong)NSMutableArray
*history;
@property (nonatomic,strong)NSMutableArray
*plusbts;
@property (nonatomic,
weak) IBOutlet
UIButton *buttonMyPhrase;
//<! マイフレーズボタン
@property (nonatomic,
weak) IBOutlet
UIButton *buttonHistory;
//<! 履歴ボタン
@property (nonatomic,
weak) IBOutlet
UIView *lineView;
//<! 仕切り線
@property (nonatomic,
weak) IBOutlet
UITableView *phraseTableView;
//<! フレーズ表示テーブル
@property (nonatomic,
strong) UIImage *plusButtonImageNormal;
@property (nonatomic,
strong) UIImage *plusButtonImageHighlighted;
@end
@implementation MyPhraseTabViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
self.view.backgroundColor = [UIColor
whiteColor];
// buttons
self.buttonMyPhrase.tag
= TabButtonTagMyPhrase;
self.buttonHistory.tag
= TabButtonTagHistory;
self.buttonMyPhrase.exclusiveTouch
=
self.buttonHistory.exclusiveTouch
= YES;
// デフォルトはマイフレーズ表示
[self
changeButtonWithSelectedButtonTag:TabButtonTagMyPhrase];
// line
self.lineView.backgroundColor
= [UIColor
customColorWithRed:105
green:204
blue:204];
// table
self.phraseTableView.dataSource
= self;
self.phraseTableView.delegate
= self;
self.phraseTableView.separatorStyle
= UITableViewCellSeparatorStyleNone;
// cell
[self.phraseTableView
registerNib:[UINib
nibWithNibName:NSStringFromClass([PhraseDisplayCell
class]) bundle:[NSBundle
mainBundle]]
forCellReuseIdentifier:PhraseDisplayCellID];
self.plusButtonImageNormal = [UIImage
imageNamed:@"bt_14_02"];
self.plusButtonImageHighlighted = [UIImage
imageNamed:@"bt_14_02_p"];
//データを取ります
TranslationDataManager *tdm = [TranslationDataManager
sharedInstance];
//日本語履歴
NSArray *historyList = [tdm
getJaHistoryList];
for (int i =
0;i < historyList.count;i++) {
[self.history
addObject:historyList[i]];
}
// マイフレーズ
NSArray *myPhraseList = (NSArray*)[tdm
getMyPhraseList];
for (int i =
0; i < myPhraseList.count;i++){
[self.myphrase
addObject:myPhraseList[i]];
}
// 長押しアクション
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer
alloc] initWithTarget:self
action:@selector(longPressGestureRecognized:)];
[self.phraseTableView
addGestureRecognizer:longPress];
}
- (void) viewDidAppear:(BOOL)animated
{
[super
viewDidAppear:animated];
// //先頭表示のためリロード
// [self.phraseTableView reloadData];
}
- (void)viewWillDisappear:(BOOL)animated
{
// DBにマイフレーズを保存
[[TranslationDataManager
sharedInstance]
setMyPhraseList:(NSArray *)self.myphrase];
[super
viewWillDisappear:animated];
}
# pragma mark - button callbacks
- (void) tabButtonTapped:(id)sender
{
if(sender ==
self.buttonMyPhrase) {
[self
changeButtonWithSelectedButtonTag:TabButtonTagMyPhrase];
}
else
if(sender == self.buttonHistory) {
[self
changeButtonWithSelectedButtonTag:TabButtonTagHistory];
}
[self.phraseTableView
reloadData];
}
-(void)longPressGestureRecognized:(id)sender
{
if(selectedTab_ ==
TabButtonTagHistory) {
return;
}
UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender;
UIGestureRecognizerState state = longPress.state;
CGPoint location = [longPress
locationInView:self.phraseTableView];
NSIndexPath *indexPath = [self.phraseTableView
indexPathForRowAtPoint:location];
static
UIView *snapshot =
nil;
static
NSIndexPath *sourceIndexPath =
nil;
switch (state) {
//移動が始まります
case
UIGestureRecognizerStateBegan:
if (indexPath){
sourceIndexPath = indexPath;
GlossaryTableViewCell *cell3 = [self.phraseTableView
cellForRowAtIndexPath:indexPath];
snapshot = [self
customSnapshoFromView:cell3];
__block
CGPoint center = cell3.center;
snapshot.center = center;
snapshot.alpha =
0.9;
[self.phraseTableView
addSubview:snapshot];
[UIView
animateWithDuration:0.25
animations:^{
center.y = location.y;
snapshot.center = center;
snapshot.transform =
CGAffineTransformMakeScale(1.05,
1.05);
snapshot.alpha =
0.9;
cell3.hidden =
YES;
[self.phraseTableView
reloadData];
}];
}
break;
case
UIGestureRecognizerStateChanged:{
//移動中
CGPoint center = snapshot.center;
center.y = location.y;
snapshot.center = center;
if (indexPath && ![indexPath
isEqual:sourceIndexPath]){
[self.myphrase
exchangeObjectAtIndex:indexPath.row
withObjectAtIndex:sourceIndexPath.row];
[self.phraseTableView
moveRowAtIndexPath:sourceIndexPath
toIndexPath:indexPath];
sourceIndexPath = indexPath;
}
break;
}
default:{
//移動しました
GlossaryTableViewCell *cell4 = [self.phraseTableView
cellForRowAtIndexPath:sourceIndexPath];
cell4.alpha =
0.9;
[UIView
animateWithDuration:0.25
animations:^{
snapshot.center = cell4.center;
snapshot.transform =
CGAffineTransformIdentity;
snapshot.alpha =
0.9;
cell4.alpha =
1.0;
}completion:^(BOOL finished) {
cell4.hidden =
NO;
sourceIndexPath = nil;
[snapshot removeFromSuperview];
snapshot = nil;
}];
[self.phraseTableView
reloadData];
break;
}
}
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
LogDebug(@"numberofrow %zd", (selectedTab_
== TabButtonTagMyPhrase) ?
_myphrase.count :
_history.count);
return (selectedTab_ ==
TabButtonTagMyPhrase) ?
_myphrase.count :
_history.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
PhraseDisplayCell *cell = [tableView
dequeueReusableCellWithIdentifier:PhraseDisplayCellID];
cell.accessoryType =
UITableViewCellAccessoryNone;
cell.labelPhrase.textColor = [UIColor
customColorWithRed:102
green:102
blue:102];
cell.labelPhrase.font = [UIFont
MecTraFontOfSize:17.0];
cell.separatorView.backgroundColor = tableView.separatorColor;
if(selectedTab_ ==
TabButtonTagMyPhrase) {
// マイフレーズ表示
cell.labelPhrase.text =
self.myphrase[indexPath.row];
[cell setButtonHidden:YES];
}
else {
// 履歴表示
cell.labelPhrase.text =
self.history[indexPath.row];
[cell.buttonPlus
setImage:self.plusButtonImageNormal
forState:UIControlStateNormal];
[cell.buttonPlus
setImage:self.plusButtonImageHighlighted
forState:UIControlStateHighlighted];
[cell.buttonPlus
addTarget:self
action:@selector(addDataToMyPhrase:)
forControlEvents:UIControlEventTouchUpInside];
cell.buttonPlus.tag = indexPath.row;
[cell setButtonHidden:NO];
}
return cell;
}
- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath
*)indexPath
{
LogDebug(@"編集%@",
selectedTab_ ==
TabButtonTagMyPhrase ?
@"可能" :
@"不可");
return (selectedTab_ ==
TabButtonTagMyPhrase) ?
true : false;
}
# pragma mark - UITableView delegate methods
//tableview1の削除機能を追加する
-(NSArray <UITableViewRowAction *> *)tableView:(UITableView *)tableView
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedTab_ ==
TabButtonTagMyPhrase) {
UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@"削除"
handler:^(UITableViewRowAction * action,
NSIndexPath * indexPath) {
[self.myphrase
removeObjectAtIndex:indexPath.row];
[self.phraseTableView
deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.phraseTableView
reloadData];
}];
[[TranslationDataManager
sharedInstance]
deleteMyPhrase:_myphrase[indexPath.row]];
return
@[deleteRowAction];
}
else {
return
nil;
}
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return
44;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
_dataString = (selectedTab_ ==
TabButtonTagMyPhrase) ?
_myphrase[indexPath.row] :
_history[indexPath.row];
NSNotificationCenter *center = [NSNotificationCenter
defaultCenter];
[center postNotificationName:@"cesuo"
object:_dataString];
//翻訳中画面を表示する
MBProgressHUD.langCode =
@"ja";
[MBProgressHUD
showMessage:@""];
[self.navigationController
popToRootViewControllerAnimated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
}
# pragma mark - local methods
- (void) changeButtonWithSelectedButtonTag:(TabButtonTag)tag
{
if(tag ==
TabButtonTagMyPhrase) {
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"pt_13_01"]
forState:UIControlStateNormal];
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"pt_13_01"]
forState:UIControlStateHighlighted];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"bt_13_01"]
forState:UIControlStateNormal];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"bt_13_01_p"]
forState:UIControlStateHighlighted];
// target
[self.buttonMyPhrase
removeTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[self.buttonHistory
addTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
}
else {
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"bt_14_01"]
forState:UIControlStateNormal];
[self.buttonMyPhrase
setBackgroundImage:[UIImage
imageNamed:@"bt_14_01_p"]
forState:UIControlStateHighlighted];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"pt_14_01"]
forState:UIControlStateNormal];
[self.buttonHistory
setBackgroundImage:[UIImage
imageNamed:@"pt_14_01"]
forState:UIControlStateHighlighted];
// target
[self.buttonMyPhrase
addTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[self.buttonHistory
removeTarget:self
action:@selector(tabButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
}
selectedTab_ = tag;
}
-(UIView *)customSnapshoFromView:(UIView *)inputView
{
//inputviewにimageを作る
UIGraphicsBeginImageContextWithOptions(inputView.bounds.size,
NO,
0);
[inputView.layer
renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//image view
UIView *snapshot = [[UIImageView
alloc] initWithImage:image];
snapshot.layer.masksToBounds =
NO;
snapshot.layer.cornerRadius =
0.0;
snapshot.layer.shadowRadius =
5.0;
snapshot.layer.shadowOpacity =
1;
return snapshot;
}
- (void) addDataToMyPhrase:(UIButton *)button
{
//重複はさせない
for (int i=0;i<_myphrase.count;i++){
if ([_myphrase[i]
compare:_history[button.tag]] ==
NSOrderedSame) {
[self.view
makeToast:@"マイフレーズに登録済みです。"];
return;
}
}
[self.view
makeToast:@"マイフレーズに登録しました。"];
//履歴から追加
[_myphrase
addObject:_history[button.tag]];
[[TranslationDataManager
sharedInstance]
addMyPhrase:_history[button.tag]];
[self.phraseTableView
reloadData];
}
//deleteDataのインスタンスを作る
-(NSMutableArray *)myphrase
{
if (_myphrase ==
nil) {
_myphrase = [NSMutableArray
array];
}
return
_myphrase;
}
//deleteData3のインスタンスを作る
-(NSMutableArray *)history
{
if (_history ==
nil) {
_history = [NSMutableArray
array];
}
return
_history;
}
@end
相关文章推荐
- Android 一个按钮两次单击触发两个不同事件并实现两个View在同一界面切换
- 做一个计时器示例 在页面上有一个文本框和一个普通按钮 在状态栏上显示,单击按钮,开始计时的提示信息 单击按钮时,在文本框显示计数的过程,同时要求按钮上的字,显示为“单击暂停” 此时单击按钮,暂停计时,同时按钮上的字显示为“继续计时”,要求这两种状态来回切换,来完成计数器的功能
- 一个tableView的Cell中有两个点击按钮及tableView的重用
- 同一个activity中通过一个按钮切换两个不同的布局
- 在imageView依次添加7个手势, 1.点击哪个按钮,往imageView上添加哪个手势.(保证视图上只有一个手势). 2.轻拍:点击视图切换美女图片.(imageView上首先展示的美女
- ios:点击tableView中的一个按钮,确定cell所在的行
- 网页中有两个table, 默认只显示第一个table,点击一个按钮后显示第二个table,第一个table隐藏
- 一个界面中如何使用两个tableView
- 【代码笔记】iOS-一个tableView,两个section
- ios 如何让TableView加入横向滑动出现删除按钮的功能
- 实现类似QQ聊天列表的segment点击切换tableView的数据功能
- 如何使用一个按钮实现两个功能
- 如何在一个view上 显示两个tableview
- ios 如何让TableView加入横向滑动出现删除按钮的功能
- 一个界面中使用两个tableView
- 一个界面中如何使用两个tableView
- C#第十周任务之最后一项之创建一个如下的窗体,并在窗体上放置一个菜单、一个工具栏控件。菜单内容如第二个图所示。工具栏上有两个按钮,分别对应“打开文本文件”、“保存文本文件”。菜单和工具栏具体功能实现可
- 多表-连表筛选代码(其中一个view有两个表格tableView)
- iOS如何在一个view上 显示两个tableview