내 응용 프로그램에 대한 "설정"테이블보기를 만들려고합니다. 나는 아이폰에 일반 설정과 같은 스타일로 그것을 모방하려고합니다. UITableCell에서 상속하여 내 자신의 사용자 지정 셀 클래스를 만들었습니다. 적절한 IBOulet을 주었고 스토리 보드에 연결했습니다. 나는 또한 내 tableViewControler에 스위치를 연결했지만 몇 가지 이유로 내 코드는 하나의 빈 셀만 리턴한다. (단 하나의 셀만이 내 설정에있는 모든 ATM에 문제가되지 않는다.) 나는 트리플을 점검하고 코드와 스토리 보드에서 동일한 셀 식별자를 사용하고 있는지 확인했습니다. 왜 내가 빈 셀을 돌려 받는지 누가 알 겠어?IOS 정적 테이블 사용자 지정 셀 전용 무작위 셀을 그립니다.
내 사용자 정의 셀에 대한 .h 파일이 있습니다.
@interface NHPSettingsCell : UITableViewCell
@property (nonatomic,weak) IBOutlet UILabel *settingLabel;
@property (nonatomic,strong) IBOutlet UISwitch *settingSwitch;
@end
내 문제 코드, 여기에 사용자 정의 셀 내 .H 파일입니다
#import "NHPSettingsCell.h"
@implementation NHPSettingsCell
@synthesize settingLabel, settingSwitch;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
내 사용자 정의보기 컨트롤러 셀을 그리기에 대한 나의 방법 : 이제
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SettingsCell";
NHPSettingsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[NHPSettingsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellStyleDefault;
}
cell.settingLabel.text = @"firstSetting";
//check the if user wants promt of disclaimer each time or not.
if([prefs boolForKey:@"firstSetting"] == YES){
cell.settingSwitch.on = YES;
}else{
cell.settingSwitch.on = NO;
}
return cell;
}
나를 귀찮게하는 건 내가 성공적으로 사용자 정의 셀을 사용하는 동적 테이블에 대한 cellForRowAtIndexPath 메소드를 구현할 수 있었기 때문입니다. 또한 기본 셀을 사용하는 정적 테이블의 코드를 구현했지만 사용자 정의 셀이있는 정적 테이블의 경우에는 작동하지 않는 것 같습니다. 다음은 동적 테이블에 내 사용자 정의 셀을 구현 한 코드입니다 (셀을 초기화 할 필요는 없지만 작동하는 방식에 유의하십시오).
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"InteractionResultCell";
NHPResultCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure & Fill the cell
cell.leftLabel.text = [[resultsList objectAtIndex:indexPath.row] substanceName];
cell.rightLabel.text = [[resultsList objectAtIndex:indexPath.row] substanceName2];
NSString *color = [NSString stringWithFormat:@"%@", [[resultsList objectAtIndex:indexPath.row] color]];
//Change a hex value to a readable 0x number to pass ot hte macro so we can go from a hex color to a RGB system.
NSScanner *scanner;
unsigned int tempint=0;
scanner = [NSScanner scannerWithString:color];
[scanner scanHexInt:&tempint];
cell.severityButton.backgroundColor = UIColorFromRGB(tempint);
return cell;
}
그게 효과가있다. 고맙습니다. – user597608
initWithCOder 사용법에 대한 몇 가지 코드를 제공 할 수 있습니까? awakeFromNib와 동일합니다. 나는 물어 보는 것에 대해 사과하지만이 코드는 곧 발표 될 예정이며 atm 기능을 깨뜨리는 것이 두려워요. – user597608
이것은 표준 init 메소드입니다. self = [super initWithCoder : aDecoder]; if (self) 등등 awakeFromNib도 표준 방법입니다. 내가 어떤 견본을 줄 수 있는지 모르겠다. – jrturton