UITableView에 사용자 지정 셀을 사용하고 있는데 UIButton이 있습니다. 버튼을 터치 할 때마다 제목을 토글하고 싶습니다. 내가 첫 번째 셀에있는 버튼을 클릭 할 때마다 내가 뭔가를 하나 개의 조건을 제외한 모든 사용자 정의 셀에 대해 잘 작동사용자 지정 셀의 UIButton 제목을 업데이트 할 수 없습니다.
-(void) addingToPortfolio:(id) sender
{
NSLog(@"In FADymanicCellTable");
foundInPortfolio = [TOperations foundInPortfolio:selectedSymbol];
tempButton = (UIButton*)[self.view viewWithTag:self.selectedPath.row];
NSLog(@"Self selected path row = %ld", (long)self.selectedPath.row);
NSLog(@"Button tag = %d", tempButton.tag);
if (foundInPortfolio)
{
NSLog(@"Removing From Portfolio");
[TOperations deleteFromPortfolio:selectedSymbol];
tempButton.titleLabel.font = [UIFont systemFontOfSize:12];
[tempButton setTitle:@"Add To Portfolio" forState:UIControlStateNormal];
}
else
{
NSLog(@"Adding to Portfolio");
[TOperations addToPortfolio:selectedSymbol];
tempButton.titleLabel.font = [UIFont systemFontOfSize:10];
[tempButton setTitle:@"Remove From Portfolio" forState:UIControlStateNormal];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CellIdentifier";
NSLog(@"Creating Cell");
FADynamicCell *cell= (FADynamicCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([FADynamicCell class])
owner:nil
options:nil] lastObject];
}
switchButton = [UIButton buttonWithType:UIButtonTypeCustom];
switchButton.tag = indexPath.row;
// switchButton.titleLabel.tag = indexPath.row;
NSLog(@"Swithch Button Tag = %ld",(long)switchButton.tag);
switchButton.frame = cell.addToPFButton.frame;
switchButton.backgroundColor = [UIColor colorWithRed:102./255 green:204./255 blue: 255./255 alpha:1];
switchButton.titleLabel.numberOfLines = 2;
switchButton.titleLabel.font = [UIFont systemFontOfSize:12];
switchButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[switchButton setTitle:@"Remove From Portfolio" forState:UIControlStateNormal];
[switchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[switchButton addTarget:self action:@selector(addingToPortfolio:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:switchButton];
return cell;
}
그리고 기능 addingToPortfolio에서
을하고있는 중이 야 cellForRowAtIndexPath에서추락되어 오류가 표시됩니다.
-[UIView titleLabel]: unrecognized selector sent to instance 0x86e4850
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView titleLabel]: unrecognized selector sent to instance 0x86e4850'
도움 말 b 기본적으로 UIView의 인스턴스 따라서 라인 0으로 동일한 태그를 가지고 있기 때문에 전자 평가는 ...
태그 값이 0 인 UIButton을 얻지 못했다고 생각합니다. 그렇다면 switchButton.tag = indexPath.row + 1을 설정하고 이에 따라 UIButton을 검색하십시오. – Bhavesh
@ iBhavesh : 태그 값이 0 인 UIButton이 표시됩니다. 메소드 - (void) addingToPortfolio : (id) 보낸 사람이 충돌하기 전에 단추 태그 = 0을 인쇄합니다. – Atul