Added support for storyboard in coreplot demo

Source: Internet
Author: User

CorePlotDemo code is a demo program of CorePlot graph, pie chart, and columnar Statistical Chart library. Use xib as the UI


The procedure is as follows:

1. Delete the mainwindow. xib file first.

2. modify main. m

Main function:

# Import "CorePlotDemoAppDelegate. h" // introduce the header file
Int main (int argc, char * argv []) {

// NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init];
@ Autoreleasepool {
ReturnUIApplicationMain (argc, argv, nil, NSStringFromClass ([CorePlotDemoAppDelegateclass]);
}
 
// [Pool release];
}

3. Create a storyboard File


4. Set project properties to load from the storyboard File

Select Main Storyboard under "CorePlotDemo"-"Summary" to set the new storyboard file.


5. in the storyboard file, create a tabBarController container, and create three new viewcontrollers, tabBarController, and three viewcontrollers (right-click control, and draw lines to each viewController. Select the first option in the pop-up menu ), set the identifier attribute of tabBarController to tabBarController.


6. Three viewcontrollers (rootViewController, pieChartViewController, and barChartViewController) are associated with the class file (RootViewController, PieChartViewController, BarChartViewController)


7. After the association is established, modify the code and control the display of three vewcontrollers from the code.

Modify the source code file CorePlotDemoAppDelegate. m.

7.1 modify as follows, and the code between the following/**/remains unchanged

/* The intermediate code remains unchanged at www.2cto.com.

// 1. initialize rootViewController
Self. rootViewController = [[RootViewController alloc] init] autorelease];

// 2. Construct the controllers View
BarChartViewController * barChart = [[BarChartViewControlleralloc] init];
PieChartViewController * pieChart = [[PieChartViewControlleralloc] init];
NSArray * controllers = [[NSArrayalloc] initWithObjects: self. rootViewController, barChart, pieChart, nil];
[BarChartrelease];
[PieChartrelease];

// 3. Set entries on the tabBar
UITabBarItem * tabBarItemOne = [[UITabBarItemalloc] initWithTitle: @ "Scatter" image: nil tag: 0];
UITabBarItem * tabBarItemTwo = [[UITabBarItemalloc] initWithTitle: @ "Pie" image: nil tag: 1];
UITabBarItem * tabBarItemThree = [[UITabBarItemalloc] initWithTitle: @ "Bar" image: nil tag: 2];
*/

7.1.1 comment the following line

// TabBarController = [[UITabBarController alloc] init]; // we have drawn UITabBarController on the storyboard.


7.1.2 Add the following code for Modification
NSString * tbControllerId = @ "tabBarController ";
UIStoryboard * sb = [UIStoryboardstoryboardWithName: @ "baStoryboard" bundle: nil]; // get the storyboard object pointer
UITabBarController * tbController = [sbinstantiateViewControllerWithIdentifier: tbControllerId]; // obtain tabbarcontroller
TbController. viewControllers = controllers;
[[TbController. viewControllersobjectAtIndex: 0] setTabBarItem: tabBarItemOne];
[[TbController. viewControllersobjectAtIndex: 1] setTabBarItem: tabBarItemTwo];
[[TbController. viewControllersobjectAtIndex: 2] setTabBarItem: tabBarItemThree];

At this time, three viewcontrollers have been set in tabBarController of storyboard. Run the command to display the view in tabBarController.

 


From gaoxuefeng's column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.