당신이 당신의 버튼에 태그를 제공하려고 (가 고유한지 확인) 할 수 있습니다.
버튼에 태그 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;
}
후 이 단추를 누르십시오 단추 배경색을 빨간색으로 설정합니다.
@christina 도움이 될 것입니다. – Gypsa
세부 사항을 말하면 이해할 수 없습니다. 하나의보기에서 테이블보기가 있고 다른보기에서 테이블보기가 있습니다. 어떻게 하나의 테이블보기에서 uibutton 사전 설정에 액세스 할 수 있습니까? 다른보기에서보기 – Christina
고유 태그가있는 단추를 만들어야만 1table보기에서 만든 것으로 가정 할 수 있습니다. 이제 어디에서 그 버튼에 액세스하고 싶습니까? UIButton * button = (UIButton *) [self.view viewWithTag : 49]; 그것은 당신의 버튼에 대한 참조를 줄 것입니다. 그리고 이제 당신은 당신이 이미지 변화 또는 어떤 것과 같은 버튼으로 할 수있는 것을 할 수 있습니다. – Gypsa