Завершение приложения из-за неперехваченного исключения «NSRangeException», причина: «*** -[NSArray objectAtIndex:]: индекс 2 за пределами пустого массива»
Мой код выглядит следующим образом:
UICustomSwitch.h
Код: Выделить всё
#import
@interface UICustomSwitch : UISwitch {
}
-(void)setLeftLabelText:(NSString *)labelText;
-(void)setRightLabelText:(NSString *)labelText;
@end
Код: Выделить всё
#import "UICustomSwitch.h"
@implementation UICustomSwitch
-(UIView *)slider {
return [[self subviews ] lastObject];
}
-(UIView *)textHolder {
return [[[self slider] subviews]objectAtIndex:2];
}
-(UILabel *)leftLabel {
return [[[self textHolder] subviews]objectAtIndex:0];
}
-(UILabel *)rightLabel {
return [[[self textHolder] subviews]objectAtIndex:1];
}
-(void)setLeftLabelText:(NSString *)labelText;
{
[[self leftLabel] setText:labelText];
}
-(void)setRightLabelText:(NSString *)labelText {
[[self rightLabel]setText:labelText];
}
@end
Код: Выделить всё
UICustomSwitch* switchView=[[[UICustomSwitch alloc]initWithFrame:CGRectMake(200,5,90,30)]autorelease];
[switchView setLeftLabelText:@"F"];
[switchView setRightLabelText:@"M"];
[switchView addTarget:self action:@selector(genderAction:) forControlEvents:UIControlEventValueChanged];
[elementView addSubview:switchView];
Подробнее здесь: https://stackoverflow.com/questions/624 ... -exception
Мобильная версия