내 cellForRowAtIndex에서 나는 버튼 (그것이있는 tableview의 모든 셀에 표시됩니다) 초기화된다버튼을 클릭 한 후 이미지를 변경하기로되어 있지만, (무작위로) 다른 버튼의 이미지를 변화도
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(customActionPressed:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0f,cell.frame.size.height -15, 160.0f, 15.0f);
UIImage *buttonImage = [UIImage imageNamed:@"Image1.png"];
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[button.titleLabel setFont:[UIFont fontWithName:@"Arial" size:13.0]];
button.contentEdgeInsets = UIEdgeInsetsMake(1, 60, 0, 0);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[cell addSubview:button];
button.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
그것은이를 일반 이미지이며 사용자가 버튼을 클릭하면 이미지가 변경됩니다. 또한 XML에서 button.title의 내용을 가져옵니다. 따라서 나는 웹에서 올바른 제목을 얻으라고 말한다. 이 잘 작동하지만 때로는 (모든 시간) 또한 무작위로 다음 셀 또는 셀 세 줄에서 단추를 변경합니다. 나는 이유를 모르며 중단 점/디버거로 실행하는 동안 아무 것도 찾을 수 없습니다.
-(void)customActionPressed :(id)sender
{
UITableViewCell *owningCell = (UITableViewCell*)[sender superview];
NSIndexPath *pathToCell = [self.tableView indexPathForCell:owningCell];
UIImage *buttonImage = [UIImage imageNamed:@"image2.png"];
[self doXMLParsing];
[sender setBackgroundImage:buttonImage forState:UIControlStateNormal];
NSString *TableText = [[NSString alloc] initWithFormat:@"%@", [[tabelle objectAtIndex:pathToCell.row] pressed1]];
[sender setTitle:TableText forState:UIControlStateNormal];
((UIButton *)sender).enabled = NO;
}
어쩌면 누군가 내가 잘못 된 곳을 볼 수 있습니다. 더 많은 코드가 필요한 경우 그렇게 말하십시오.
두 번째 부분에 대해 자세히 설명해 주시겠습니까? 나는 내가 정말로 undertsand하지 않는다라고 생각한다. – Blade
customcell을 만들 때 [cell.nameofyourbutton setImage : [UIIMAGE imageNamed : @ ""]];에 액세스 할 수 있습니다. 셀에 여러 항목이있는 경우 변경을하고 쉽게 액세스 할 수 있으므로 맞춤 설정하는 것이 좋습니다. –
오, 알겠습니다. 이해합니다. 그러나 그것이 appdelegate 임에도 불구하고 "cell.mybutton"으로 무엇을해야하는지 알지 못합니다. – Blade