내 맞춤 검색 버튼을 만들고 아래 코드와 같이 버튼 번호를 제공하고 있습니다. 나는 10 개의 행이있는 테이블을 가지고 있고 행 1-5 버튼을 터치 할 때 나는 내 로그uitabelview 맞춤 검색 버튼 태그 문제
[button tag]: 100 ...
[button tag]: 101 ...
[button tag]: 102 ...
[button tag]: 103 ...
[button tag]: 104 ...
에서 다음을받을 경우
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"Inside cellForRowAtIndexPath");
static NSString *CellIdentifier = @"Cell";
// Try to retrieve from the table view a now-unused cell with the given identifier.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// If no cell is available, create a new one using the given identifier.
if (cell == nil)
{
// Use the default cell style.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(selectPicOnBtnTouch:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"btn1" forState:UIControlStateNormal];
button.frame = CGRectMake(6.0f, 0.0f, 97.0f, 110.0f);
button.tag = (indexPath.row)+100;
[cell addSubview:button];
[button setImage:[UIImage imageNamed:@"sample_pic.png"] forState:UIControlStateNormal];
}
else
{
//NSLog(@"went here 2");
button = (UIButton *) [cell viewWithTag:((indexPath.row)+100)];
}
//Get an arrow next to the name
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
- (IBAction) selectPicOnBtnTouch:(id)sender
{
button = (UIButton *)sender;
NSLog(@"[button tag]: %d ...", [button tag]);
}
이 괜찮습니다. 문제는 내가 행 6-10을 터치하면 내가 105 개 기대하고 있다는 것입니다 - 시작 동일한 태그 번호를 109 태그를하지만 내가 돌아올 것은
나는 독특한 (그리고 반복하지 태그 번호를 유지하려는 이유
[button tag]: 100 ...
[button tag]: 101 ...
[button tag]: 102 ...
[button tag]: 103 ...
[button tag]: 104 ...
이상) 그래서 어떤 버튼이 어떤 행에 해당하는지 알 수 있습니다. 어떻게해야합니까?
+1은 메모리 관리에 대한 설명입니다. 많은 사용자가 메모리 관리에 나쁜 영향을 줄 때도 알려주지 않습니다. – Popeye
@ Popeye- 초심자에게 감사합니다. :) – iPatel
많은 사용자가 재사용 가능한 셀을 이해하지 못하고 문제를 일으키지 않고 원하는만큼 많은 셀을 만들 수 있다고 생각합니다. – Popeye