성공적으로 "셀"개체 (UITableViewCell 기반)를 만들었으며 cellForRowAtIndexPath을 통해 테이블을 만들 때 성공적으로 사용했습니다.XCODE에서 내 자체 Cell 객체 사용
그러나 내가 수행 한 작업을 어떻게 해체합니까? didSelectRowAtIndexPath?
나는 현재
이내 객체 (MyCell)이있는 UITableViewCell에 기초하고 내가 왜 이해하지 않는다 " '있는 UITableViewCell'유형의 식 '* __ 강력한 MyCell를'초기화 호환되지 않는 포인터 타입"오류 를받을 이 오류가 발생합니다.
내가 뭘 잘못하고 있는지 이해해 주시겠습니까?
나의 대안은 셀의 두 레이블 각각에 "태그"를 사용하여 그러한 방식으로 가져 오는 것입니다. 그러나이 모든 것이 어떻게 작동하는지 더 자세히 알기 위해 여기에서 실험하고 있습니다.
도움을 주시면 감사하겠습니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"myCellID";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[MyCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.accountCode.text = @"0009810";
cell.accountName.text = @"Agent Name";
return cell;
}
다른 방법이 있습니다. 오류가 발생했습니다 MyCell * cell = [tableView cellForRowAtIndexPath : indexPath]; 여기
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Get the cell that was selected
MyCell *cell = [tableView cellForRowAtIndexPath:indexPath];
AccountRecord *accountRecord = [[AccountRecord alloc] init];
accountRecord.accountCode = cell.accountCode.text;
accountRecord.accountName = cell.accountName.text;
[self performSegueWithIdentifier:@"AccountDetail" sender:accountRecord];
}
그리고는 어떤 도움을 주시면 감사하겠습니다 MyCell
#import <UIKit/UIKit.h>
@interface MyCell : UITableViewCell
@property (nonatomic,strong) IBOutlet UILabel *accountCode;
@property (nonatomic,strong) IBOutlet UILabel *accountName;
@end
입니다.
와우. 그거 쉽지? 그래서 이것은 기본적으로 내 객체에 결과를 "캐스팅"하는 것입니까? – David
예, 맞춤형 셀을 사용 중이므로 캐스팅해야합니다. – user427969
우수. 그것은 트릭을했다. 내 게시물에 대한 거의 즉각적인 답변을 보내 주셔서 감사합니다. :-) – David