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];

   }

在 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

提前致以问候和感谢。

4

1 回答 1

0

您可以使用的东西(尽管我不知道这是否是最好的方法)是在viewDidLoad方法中加载视图时为按钮设置默认图像。所以就:

-(void)viewDidLoad
{
    //Whatever you have in here...
     yourButtonName setImage: [UIImage imageNamed:@"addtochatNormal.png"];
    [super viewDidLoad];
}

或类似的规定。

如果我没有正确回答您的问题,请告诉我。

于 2013-07-18T02:43:40.317 回答