更新
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];
}
但它仍然不起作用,这一次 somefunction 甚至没有被调用,因为 NSlog 没有像第一次那样出现。
问候