質問

In my iPhone app I have used an UI Segment Controller with three segments.
I need to add a subView already created to the second segment,

for this I have used follow code

[segment addSubview:ImgVw forSegment:1];

[segment addSubview:BlueButton forSegment:3];

it prompts a warning

instance method addSubView for segment not found return type defaults to id

And crashes the app

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISegmentedControl addSubview:forSegment:]: unrecognized selector sent to instance 0x8a8a7a0'

I need to add different subViews for different segments in UISegment controller at many places

how?

役に立ちましたか?

解決

There is not method That allow you to insert UiView at particular segment in my opinion.

But you can set custom image plz have a look to below Code

NSArray *arrItem=[[NSArray alloc]initWithObjects:@"1", @"2",@"3",@"4",nil];
    UISegmentedControl *seg=[[UISegmentedControl alloc]initWithItems:arrItem];
    seg.frame=CGRectMake(10, 100, 300, 200);
    [seg insertSegmentWithImage:[UIImage imageNamed:@"SearchTransparent.png"] atIndex:2 animated:YES];
    [seg setWidth:90.0 forSegmentAtIndex:2];
    [self.view addSubview:seg];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top