0
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];
}
在h文件的viewcontroller B我有:
#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;在视图中会出现,因为我的视图控制器如何工作
提前感谢和感谢。
再次尝试我看到...某些功能会被调用吗?你尝试重新加载整个表,而不是尝试重新加载旧的选定索引? – Bogatyr
再次感谢您的解决方案,再一次是因为我如何改变视图控制器 – snowleopard