viewcontroller A 去 B 然后回到 A。我有一个 UIButton,在 viewcontrollerA 的 UItableview 的每个单元格中。当您单击该按钮时,该按钮突出显示并转到 viewcontrollerB。当您返回 viewcontrollerA 时,我希望取消选择按钮。按钮的突出显示效果很好是取消选择是问题。
在 cellforrowatindexpath 中,我有这个:
if(indexPath.row==selectedbuttonindex)
{
addpeople.selected=YES;
}
else
{
addpeople.selected=NO;
}
UIImage *buttonImageNormal =[UIImage imageNamed:@"addtochatNormal.png"];
UIImage *buttonImageSelected =[UIImage imageNamed:@"addtochatSelected.png"];
[addpeople addTarget:self action:@selector(addpeopletoChat:)
forControlEvents:UIControlEventTouchDown];
[addpeople setBackgroundImage:buttonImageSelected forState:UIControlStateHighlighted];
[addpeople setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
[addpeople setBackgroundImage:buttonImageSelected forState:UIControlStateSelected];
addpeople.frame = CGRectMake(0,0, 51, 44);
[cell.contentView addSubview:addpeople];
通过以下方法实现按钮的选择和视图控制器的更改:
-(void) addpeopletoChat : (UIButton*)button{
UITableViewCell *cell_ = (UITableViewCell *)button.superview.superview;
NSIndexPath *index_Path = [topictableView indexPathForCell:cell_];
NSLog(@"%@", index_Path);
selectedbuttonindex=index_Path.row;
[topictableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index_Path] withRowAnimation:UITableViewRowAnimationFade];
countaddpeople=countaddpeople+1;
addpeopletochatViewController* viewcontrollerB = [[addpeopletochatViewController alloc] init];
viewcontrollerB.viewcontrollerA=self;
[self.slidingViewController anchorTopViewTo:ECRight];//changes view to viewcontroller B
}
这应该取消选择它
-(void) somefuction{
NSLog(@"%d", selectedbuttonindex);
NSUInteger indexArr[] = {0,selectedbuttonindex};
NSIndexPath *index_Path = [NSIndexPath indexPathWithIndexes:indexArr length:2];
selectedbuttonindex=-1;
NSLog(@"%@" @"%@", @"hi", index_Path);
[topictableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index_Path] withRowAnimation:UITableViewRowAnimationFade];
}
在 viewcontroller B 的 h 文件中,我有:
#import <UIKit/UIKit.h>
#import "officerTopicsViewController.h"
@class officerTopicsViewController;
@interface addpeopletochatViewController : UIViewController{
}
@property (nonatomic,retain) officerTopicsViewController *viewcontrollerA;
@end
在它的 m 文件中我有:
-(void)viewDidDisappear:(BOOL)animated
{
[viewcontrollerA somefunction];
}
但它仍然不起作用
注意:我不能把 selectedbuttonindex=-1; 由于我的视图控制器的工作方式,会出现 in view
提前致以问候和感谢。