0

头等舱

@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];
}

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

4

2 回答 2

1

在 WatchPreviewViewController 中创建类似枚举的样式并创建自己的 init 方法。

typedef 枚举 WatchPreviewViewControllerStyleType {
    WatchPreviewViewControllerStyleType1 = 0,
    WatchPreviewViewControllerStyleType2 = 1
    }WatchPreviewViewControllerStyleType;

@interface WatchPreviewViewController : UIViewController
{
    WatchPreviewViewControllerStyleType 样式;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andStyle:(WatchPreviewViewControllerStyleType)_style;

@执行


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andStyle:(WatchPreviewViewControllerStyleType)_style
{
    self.style=_style;
}

- (void)viewDidLoad
{
    [超级视图DidLoad];


    if(self.style==WatchPreviewViewControllerStyleType1)   
   {

   }
    否则如果(self.style==WatchPreviewViewControllerStyleType2)
   {
   }
}

在这个自定义初始化中设置创建控制器时发送的 ivar 样式。然后在 viewDidload 检查样式类型并为该样式添加所需的视图。

并在 WatchViewController

@implementation WatchViewController

- (void)viewDidLoad
{
    [超级视图DidLoad];
  UIButton *watch1 = [[UIButton buttonWithType:UIButtonTypeCustom] 保留];
   watch1.tag=123;
    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] 保留];
       watch1.tag=456;
    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 {

如果(发件人标签==123)
{
   WatchPreviewViewController *watchesPreviewView = [[WatchPreviewViewController alloc] initWithNibName:@"WatchPreviewViewController" bundle:nil andStyle:WatchPreviewViewControllerStyleType1];
    [self.navigationController pushViewController:watchesPreviewView 动画:YES];
    [watchesPreviewView 发布];
}
别的
{
   WatchPreviewViewController *watchesPreviewView = [[WatchPreviewViewController alloc] initWithNibName:@"WatchPreviewViewController" bundle:nil andStyle:WatchPreviewViewControllerStyleType2] ;
    [self.navigationController pushViewController:watchesPreviewView 动画:YES];
    [watchesPreviewView 发布];
}

}

于 2013-01-15T12:22:00.800 回答
1

在创建每个按钮时在每个按钮上设置标签属性(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)

于 2013-01-15T12:31:01.607 回答