objective-ctagsuikitaddsubview

How can I add a UISwitch to a specific UIScrollView?


how can I add a UISwitch to a specific UIScrollView? As I guess it can be done with a tag, but I am having difficulties.

EDIT: The problem was solved in the usual way, lol

My example code with UIScrollView and UISwitch:

@implementation NSPage {
    UIScrollView *scrolled;
    UISwitch *switchPage;
    NSInteger *keyS;
}
NSPage *page = [[NSPage alloc]init];

Here i am creating a UIScrollView and UISwitch:

-(id)initPage:(NSString *)titleScroll keyScroll:(NSInteger)keyScroll_ {
    keyS = keyScroll_;
    scrolled = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 180, 110)];
    scrolled.tag = keyS;
    scrolled.backgroundColor = [UIColor grayColor];
    [window addSubview:scrolled];
}
//get scroll tag
-(NSInteger)getScrollKey {
    return scrolled.tag = keyS;
}
//UISwitch
-(id)initSwitch:(NSString *)title_ keySwitch:(NSInteger)keySwitch_ {
    scrollSwitch += 40;
    switch_ = [[UISwitch alloc]initWithFrame:CGRectMake(15, scrollSwitch - 40, 40, 40)];
    switch_.tag = keySwitch_;
    if([self getScrollKey] == switch_.tag) {
        [scrolled addSubview:switch_];
    }
}
@end

Everything seemed to be fine, but when I add a scrolls and switches, then my UISwitch is not displayed:

page = [[NSPage alloc]initPage:@"test page" keyScroll:256];
page = [[NSPage alloc]initSwitch:@"test" keySwitch:256];

What could be my mistake, how can I add a UISwitch to a specific UIScrollView? I'm a beginner, Thanks for the help anyway


Solution

  • if([self getScrollKey] == switch_.tag) { This line does nothing take it out