gpt4 book ai didi

iphone - 我如何在 iphone 中以相同的方法加载不同的 View

转载 作者:行者123 更新时间:2023-11-28 22:41:45 25 4
gpt4 key购买 nike

头等舱

@implementation WatchViewController

- (void)viewDidLoad
{
[super viewDidLoad];UIButton *watch1 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
watch1.frame = CGRectMake(5.0, 10.0, 140.0, 170.0);
[watch1 setBackgroundImage:[UIImage imageNamed:@"Watch1.png"] forState: UIControlStateNormal];
[watch1 addTarget:self action:@selector(WatchesPreviewButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[scr addSubview:watch1];

UIButton *watch2 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
watch2.frame = CGRectMake(170.0, 10.0, 140.0, 170.0);
[watch2 setBackgroundImage:[UIImage imageNamed:@"watch2.png"] forState: UIControlStateNormal];
[watch2 addTarget:self action:@selector(WatchesPreviewButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[scr addSubview:watch2];
}

方法:

- (IBAction)WatchesPreviewButtonPressed:(id)sender {

WatchPreviewViewController *watchesPreviewView = [[WatchPreviewViewController alloc] initWithNibName:@"WatchPreviewViewController" bundle:nil];
[self.navigationController pushViewController:watchesPreviewView animated:YES];
[watchesPreviewView release];
}

第二类:

@implementation WatchPreviewViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scr=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 46, 320, 384)];
[self.view addSubview:scr];
NSArray* ds =[NSArray arrayWithObjects:
[NSArray arrayWithObjects:[self getPath:@"1a"],[self getPath:@"1b"],[self getPath:@"1c"],[self getPath:@"1d"],nil],
[NSArray arrayWithObjects:[self getPath:@"2a"],[self getPath:@"2b"],[self getPath:@"2c"],[self getPath:@"2d"],nil],nil];


SSView* sv =[SSView createWithFrame:CGRectMake(0, 0, 320, 380) ds:ds];

if(??????????????????) //what condition is required for watch1?
{
sv.curIndexPath =[NSIndexPath indexPathForRow:0 inSection:0];
[scr addSubview:sv];
}
else if(?????????????????) //what condition is required watch2?
{
sv.curIndexPath =[NSIndexPath indexPathForRow:1 inSection:0];
[scr addSubview:sv];
}

在第一个类中,我有两张 watch 图片,我想在点击 watch 时加载下一页 View 。为此,我使用方法 WatchesPreviewButtonPressed。在第二堂课中,我正在创建用于在单击按钮时加载的页面。在二等舱,我在 View 内有一个 ScrollView 。我有图像数组。我想在下次观看点击事件时显示不同的图像。任何人都请我,我是 iPhone 开发的新手。

最佳答案

(void)viewDidLoad 中创建按钮时,在每个按钮上设置标签属性:

watch1.tag = 1    //new code
[scr addSubview:watch1]; //existing code


watch2.tag = 2 //new code
[scr addSubview:watch2]; //existing code

在您的 WatchPreviewViewController.h 中,在 @interface 部分创建一个属性:

@property (assign) int watchType;

然后在 - (IBAction)WatchesPreviewButtonPressed:(id)sender 中根据按下的按钮设置属性:

watchesPreviewView.watchType = sender.tag

(您可能必须强制转换发件人:(UIView*)sender.tag,我不是在现场测试)

现在你的 if(????????????????????) 测试是 if (self.watchType == 1)

关于iphone - 我如何在 iphone 中以相同的方法加载不同的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14337460/

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