Note that there are some explanatory texts on larger screens.

plurals
  1. POUISegmentedControl change value programmatically from toolbar click
    primarykey
    data
    text
    <p>I have one .xib in which I have a view that has a UISegmentedControl and I am adding them programmatically.</p> <p>In appdelegate I have written the code for adding toolbar and there's event.<br> On toolbar click the UISegmentedControl is loaded from the given mutablearray.</p> <p>What I want to do is: when I click on toolbar button the value of UISegmentedControl cannot be changed.</p> <p>I have written a method for adding UISegment and its value. Every time on toolbar button click, I call the method.</p> <p>Method for creating UISegmentedControl:</p> <pre><code>delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; NSMutableArray *itemArray = [[NSMutableArray alloc] init]; itemArrayforID = [[NSMutableArray alloc] init]; itemArrayforImage = [[NSMutableArray alloc] init]; bool isfirst = true; UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; [segmentedControl removeFromSuperview]; int temp =0; NSLog(@"row count : %d",delegate.TopMenus.count); for(int i=0;i&lt;delegate.TopMenus.count;i++) { delegate.curTopsMenu = [delegate.TopMenus objectAtIndex:i]; NSLog(@"toolbar click : %@",delegate.toolbarbtnclick); NSLog(@"parent_id : %@",[delegate.curTopsMenu valueForKey:@"parent_id"]); if([delegate.toolbarbtnclick isEqualToString:[delegate.curTopsMenu valueForKey:@"parent_id"]]) { int aaa = [[delegate.curTopsMenu valueForKey:@"top_menu_id"] intValue]; if(isfirst) { MenuLoadID = [NSString stringWithFormat:@"%d",aaa]; isfirst =false; } NSString *TEXT = [delegate.curTopsMenu valueForKey:@"top_menu_text"]; NSString *TEXTID = [delegate.curTopsMenu valueForKey:@"top_menu_id"]; NSString *SelectIMG = [delegate.curTopsMenu valueForKey:@"image_path"]; NSLog(@" TEXT : %@ and TEXTID : %@",TEXT,TEXTID); [itemArray insertObject:TEXT atIndex:temp]; [itemArrayforID insertObject:TEXTID atIndex:temp]; [itemArrayforImage insertObject:SelectIMG atIndex:temp]; temp++; } } segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; [segmentedControl removeFromSuperview]; segmentedControl.frame = CGRectMake(0, 100, 320, 40); segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; segmentedControl.selectedSegmentIndex = 0; [segmentedControl addTarget:self action:@selector(changeSegment:) forControlEvents:UIControlEventValueChanged]; UIImage *segmentSelected = [[UIImage imageNamed:@"games-on.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; UIImage *segmentUnselected = [[UIImage imageNamed:@"games-ho.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [[UISegmentedControl appearance] setBackgroundImage:segmentUnselected forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [[UISegmentedControl appearance] setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; [self.navigationController.view addSubview:segmentedControl]; [segmentedControl release]; segmentSelected = nil; [itemArray release]; [self MenuRowCount]; </code></pre> <p>Code for toolbar button click:</p> <pre><code>ViewController *VC = [[ViewController alloc] init]; [VC LoadTopMenuFromBottmClick]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload