Reputation: 3405
I have Seprate UIView
which i am using in UIViewController
it initially loads but i want that when that is loaded and I again click on the button then it should reload because it has graph creation method which draws graph when view loaded
#import <UIKit/UIKit.h>
#import "ECGraph.h"
#import "ECGraphItem.h"
#import "CereniaAppDelegate.h"
@class GraphsViewController;
@interface Display : UIView {
NSArray *percentages;
CereniaAppDelegate*appDelegate;
}
@property(nonatomic,retain)NSArray*percentages;
-(void) setPercentageArray:(NSArray*) array;
@end
Implementation files
#import "Display.h"
#import "ECGraph.h"
#import "CereniaAppDelegate.h"
@implementation Display
@synthesize percentages;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef _context = UIGraphicsGetCurrentContext();
ECGraph *graph = [[ECGraph alloc] initWithFrame:CGRectMake(70,-70,800,200) withContext:
_context isPortrait:NO];
appDelegate=[[UIApplication sharedApplication]delegate];
ECGraphItem *item1 = [[ECGraphItem alloc] init];
ECGraphItem *item2 = [[ECGraphItem alloc] init];
ECGraphItem *item3 = [[ECGraphItem alloc] init];
item1.isPercentage = YES;
int value=(int)roundf(appDelegate.graphValueOne);
item1.yValue=value;
item1.width = 70;
item1.name = @"Unvaccinated horse";
int value1=(int)roundf(appDelegate.graphValueTwo);
item2.isPercentage = YES;
item2.yValue=value1;
item2.width = 70;
item2.name = @"Annually Vaccinated horse";
int value3=(int)roundf(appDelegate.graphValueThree);
item3.isPercentage = YES;
item3.yValue=value3;
item3.width = 70;
item3.name = @"Semi-Annually vaccinated horse";
NSArray *items = [[NSArray alloc] initWithObjects:item1,item2,item3,nil];
[graph setXaxisTitle:@""];
[graph setYaxisTitle:@"Risk"];
[graph setDelegate:self];
[graph setBackgroundColor:[UIColor lightGrayColor]];
[graph drawHistogramWithItems:items lineWidth:2 color:[UIColor blackColor]];
}
-(void) setPercentageArray:(NSArray*) array
{
percentages = array;
NSString*test=[percentages objectAtIndex:0];
NSLog(test);
}
- (void)dealloc {
[super dealloc];
}
@end
Upvotes: 3
Views: 389
Reputation: 8247
You can get any view to redraw with
[view setNeedsDisplay];
So on your refresh button you would update the data used by the Display class and then setNeedsDisplay.
Upvotes: 6