2011-06-13 6 views
0

다른보기에서보기에있는 단추에 어떻게 액세스 할 수 있습니까? 두 가지보기 컨트롤러 A 및 B가 있음을 정교하게 생각하십시오.보기 A 단추가 있습니다. 내부 테이블보기 say button1. 내 다른보기에서 테이블보기 안의 그 버튼에 액세스하고 싶습니다. 도와주세요. 나는 클래스 A의 객체를 생성 한 다음 [objA.tableview button1 write then image]라고 쓰지 만 작동하지 않습니다. 도와주세요. 어떤 도움을 주시면 감사하겠습니다.다른보기에서 테이블보기의 단추에 액세스

감사합니다, 크리스티

답변

0

당신이 당신의 버튼에 태그를 제공하려고 (가 고유한지 확인) 할 수 있습니다.

버튼에 태그 45가 있다고 가정 해 보겠습니다. 당신은 당신의 테이블보기에서 그것을 만들었습니다.

지금 다른 방법이처럼이 버튼을 사용하려면 : -

-(void)deletePostMethod 
{ 
    UIButton *button=(UIButton *)[self.view viewWithTag:49]; 
    [button setBackgroundColor:[UIColor redColor]]; 
    NSLog(@"button=%@",button); 
} 

편집 답변 : - 그 버튼을 클릭하는 방법

-(void)deletePostMethod 
{ 
    UIButton *button=(UIButton *)[self.view viewWithTag:579]; 
    [button setBackgroundColor:[UIColor redColor]]; 
    NSLog(@"button=%@",button); 
} 

- (UITableViewCell *)tableView:(UITableView *)tablefirst cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // I have added a button in my table view in first row 
    if (indexPath.row==0) { 
     UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; 
     [btn setFrame:CGRectMake(0, 0, 40, 30)]; 
     [btn addTarget:self action:@selector(deletePostMethod) forControlEvents:UIControlEventTouchUpInside]; 
     btn.tag=579; 
     [cell.contentView addSubview:btn]; 
    } 
     return cell; 
} 

후 이 단추를 누르십시오 단추 배경색을 빨간색으로 설정합니다.

+0

@christina 도움이 될 것입니다. – Gypsa

+0

세부 사항을 말하면 이해할 수 없습니다. 하나의보기에서 테이블보기가 있고 다른보기에서 테이블보기가 있습니다. 어떻게 하나의 테이블보기에서 uibutton 사전 설정에 액세스 할 수 있습니까? 다른보기에서보기 – Christina

+0

고유 태그가있는 단추를 만들어야만 1table보기에서 만든 것으로 가정 할 수 있습니다. 이제 어디에서 그 버튼에 액세스하고 싶습니까? UIButton * button = (UIButton *) [self.view viewWithTag : 49]; 그것은 당신의 버튼에 대한 참조를 줄 것입니다. 그리고 이제 당신은 당신이 이미지 변화 또는 어떤 것과 같은 버튼으로 할 수있는 것을 할 수 있습니다. – Gypsa

0

내비게이션 스택에있는 UIViewController의 모든 목록에 액세스하려면 viewControllers 속성을 사용하십시오.

@property(nonatomic, copy) NSArray *viewControllers 

NSArray* allController = self.navigationController.viewControllers ; 

for(UIViewController* myAController in allController) 
{ 
     if([myAController isMemberOfClass]) 
     { 
       //Here Now you have the A controller 
       MyViewAController* myATempController = (MyViewAController*)myAController; 

      //Now you could access the property of your A Controller. 
     } 
} 
0

버튼을보기 컨트롤러의 속성으로 지정하면 이름으로 액세스 할 수 있습니다. 사용자 인터페이스 파일에서

:

@interface MyViewController : UIViewController { 

    UIButton* myButton; 

} 

@property (nonatomic, retain) UIButton* myButton; 

@end 

구현 파일에서 :

@implementation MyViewController 

@synthesize myButton; 

@end 

그럼 당신은 당신의 버튼을 얻을 수 aViewController.myButton를 사용할 수 있습니다.

+0

이 것을 또한 시도했다 그러나 나는 얻고 있지 않다 – Christina

관련 문제