gpt4 book ai didi

iphone - 如何在单击按钮时加载 UIView

转载 作者:搜寻专家 更新时间:2023-10-30 20:00:33 25 4
gpt4 key购买 nike

我有单独的 UIView 我在 UIViewController 中使用它最初加载但我想要它加载时我再次单击按钮然后它应该重新加载因为它有图形创建方法,在加载 View 时绘制图形

  #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

执行文件

 #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

最佳答案

你可以获取任何 View 来重绘

[view setNeedsDisplay];

因此,在您的刷新按钮上,您将更新 Display 类使用的数据,然后 setNeedsDisplay。

关于iphone - 如何在单击按钮时加载 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13927699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com