2013-07-18 109 views
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;在視圖中會出現,因爲我的視圖控制器如何工作

提前感謝和感謝。

+0

再次嘗試我看到...某些功能會被調用嗎?你嘗試重新加載整個表,而不是嘗試重新加載舊的選定索引? – Bogatyr

+0

再次感謝您的解決方案,再一次是因爲我如何改變視圖控制器 – snowleopard

回答

0

你可以使用的東西(儘管我不知道這是否是最好的方法)是在viewDidLoad方法中加載視圖時,爲按鈕設置默認圖像。所以只是:

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

或沿着這些線。

如果我沒有得到你的問題,請告訴我。