지난 토요일에 비슷한 질문을하고 있었지만 현명한 사람들이 바베큐 파티에 참석 한 것처럼 보입니다. 대답을 얻지 못했습니다.iOS : 현재 TableViewCell의 현재 컨트롤을 가리키는 방법
내 문제는 UITableViewCell에 UISwitch와 두 개의 UIButton을 배치해야하며 UISwitch가 상태를 변경하면이 UIButton이 나타나거나 사라져야한다는 것입니다. 이 세포들은 어느 곳을 탐색하지되며, 따라서 나는 단지 정보 프리젠 테이션을 사용하고,에서
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
를 사용하지 않는 - (있는 UITableViewCell *)있는 tableView : (jQuery과 *)있는 tableView의 cellForRowAtIndexPath : (NSIndexPath *) indexPath methos 필요한 컨트롤을 프로그래밍 방식으로 만들고 각각에 태그 값과 액션 @selector를 할당했습니다.
다른 방법으로 현재 행에서 itemID를 가져 오는 방법을 관리했습니다. 마찬가지로이 방법 :
-(void)setItem:(UISwitch*)sender
{
int n;
UITableViewCell *cell;
if(sender.tag==9001)
{
cell=((UITableViewCell*)[sender superview]);
n=([self.tableView indexPathForCell:cell].row);
}
item=[self.arr objectAtIndex:n];
NSDate *today=[NSDate date];
NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
NSString *now =[formatter stringFromDate:today];
if(sender.on)
{
DBAccess *access=[[DBAccess alloc]init];
[access setItemON:item.itemID date:now];
//qualityBtn.hidden=NO;
[qualityBtn setTitleColor:[UIColor blackColor] forState:normal];
[qualityBtn setTitle:@"UNDEF" forState:normal];
}
else
{
DBAccess *access=[[DBAccess alloc]init];
[access setItemOFF:item.itemID];
}
}
그래서, 내 문제는이 방법이 작동 할 때이다는 qualityBtn : 다른 세포들도 등의 제목을 받고,하지만 난 전류 제어에 현재 버튼이 메소드의 로직으로 인해 변경됩니다 필요 . 그래서 현재 셀에 배치 된 컨트롤 만 변경하고 다른 셀은 생략한다는 점을 메서드에서 가리키는 방법입니다.
미리 감사드립니다.
EDIT :
@property (비 원자 강한)있는 UIButton * qualityBtn; 예, 글로벌입니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
item=[self.arr objectAtIndex:[indexPath row]];
static NSString *CellIdentifier = @"Cell";
ItemCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
self.switchView = [[UISwitch alloc] initWithFrame:CGRectMake(7, 8, 79, 27)];
[switchView addTarget:self action:@selector(setItem:) forControlEvents:UIControlEventValueChanged];
[switchView setTag:9001];
qualityBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[qualityBtn addTarget:self
action:@selector(setQuality:)
forControlEvents:UIControlEventTouchDown];
qualityBtn.frame = CGRectMake(236, 8, 72, 21);
qualityBtn.titleLabel.font = [UIFont systemFontOfSize:12];
[qualityBtn setTag:9002];
itemMemoBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[itemMemoBtn addTarget:self
action:@selector(setItemMemo:)
forControlEvents:UIControlEventTouchDown];
itemMemoBtn.frame = CGRectMake(274, 43, 34, 30);
[itemMemoBtn setTag:9003];
[itemMemoBtn setImage:[UIImage imageNamed:@"comment-icon"] forState:normal];
lblDate=[[UILabel alloc]initWithFrame:CGRectMake(14, 34, 72, 21)];
lblDate.font=[UIFont systemFontOfSize:9];
[lblDate setTag:9003];
[cell addSubview:switchView];
[cell addSubview:qualityBtn];
[cell addSubview:itemMemoBtn];
[cell addSubview:lblDate];
[cell setIndentationWidth:45];
[cell setIndentationLevel:1];
lblDate.text=item.date;
cell.lblKM.text=item.kmRef;
cell.lblInfo.text=item.info;
if(item.dateFrom.length>0 && item.dateUntil.length>0)
{
cell.lblYears.text=[NSString stringWithFormat:@"%@ - %@",item.dateFrom,item.dateUntil];
}
if(item.dateUntil.length<1)
{
cell.lblYears.text=item.dateFrom;
}
if(item.mintMark.length<1)
{
//cell.mintmarksImageView.hidden=YES;
}
cell.lblMintmarks.text=item.mintMark;
if(item.memo.length>0)
{
[email protected]"YES";
}
else
{
[email protected]"NO";
}
cell.lblRarity.text=item.rarity;
if(item.isAvailable==0)
{
[switchView setOn:NO];
//qualityBtn.hidden=YES;
//lblDate.hidden=YES;
[email protected]"UNDEF";
}
else {
[switchView setOn:YES];
// lblDate.hidden=NO;
NSString *quality=nil;
switch(item.quality)
{
case 1:
{
[email protected]"UNDEF";
break;
}
case 2:
{
[email protected]"G";
break;
}
case 3:
{
[email protected]"VG";
break;
}
case 4:
{
[email protected]"F";
break;
}
case 5:
{
[email protected]"VF";
break;
}
case 6:
{
[email protected]"XF";
break;
}
case 7:
{
[email protected]"UNC";
break;
}
case 8:
{
[email protected]"PROOF";
break;
}
}
[qualityBtn setTitleColor:[UIColor blackColor] forState:normal];
[qualityBtn setTitle:quality forState:normal];
}
return cell;
}
실제로 qualityBtn을 할당 한 코드를 표시 할 수 있습니까? 제공된 스 니펫에서 현재 개체와 관련이없는 일종의 전역 개체 인 것처럼 보입니다. –
잠깐 ... – NCFUSN
업데이트를 참조하십시오 – NCFUSN