1

私は1つの配列を持っています。その配列から画像を取得しています。配列インデックスを次のメソッドに転送したいのですが、どうすればよいですか。

私のコード:-

FrontsCards =[[NSMutableArray alloc]initWithCapacity:13];
    [FrontsCards insertObject:@"cloub1.png" atIndex:0];
    [FrontsCards insertObject:@"cloub2.png" atIndex:1];
    [FrontsCards insertObject:@"cloub3.png" atIndex:2];
    [FrontsCards insertObject:@"cloub4.png" atIndex:3];
    [FrontsCards insertObject:@"cloub5.png" atIndex:4];
    [FrontsCards insertObject:@"cloub6.png" atIndex:5];
    [FrontsCards insertObject:@"cloub7.png" atIndex:6];
    [FrontsCards insertObject:@"cloub8.png" atIndex:7];
    [FrontsCards insertObject:@"cloub9.png" atIndex:8];
    [FrontsCards insertObject:@"cloub10.png" atIndex:9];
    [FrontsCards insertObject:@"cloub11.png" atIndex:10];
    [FrontsCards insertObject:@"cloub12.png" atIndex:11];
    [FrontsCards insertObject:@"cloub13.png" atIndex:12];

すべての画像をランダムに取得し、imageviewスクロールを垂直に保存します

    randIdx=arc4random()%[FrontsCards count];

    NSString *imageName=[FrontsCards objectAtIndex:randIdx];

   [ImgView setImage:[UIImage imageNamed:imageName]];

ユーザーが cloub12.png 画像をダブルタップした場合、11 のインデックス値を生成し、それを次のビュー コントローラーに転送します。ユーザーがcloub4インデックスをタップした場合、3を生成します

よろしくお願いします。

4

5 に答える 5

3

You can pass any kind of data to anywhere in the app through creating @property in appDelegate. For example if you want to pass any integer data to some view controller.You have to create @property at the appDelegate---

in appDelegate.h----

@property(nonatomic,assign)int someObj;

in appDelegate.m-----

@synthesize someObj;

and then you can access this object where you want int the app by importing the appDelegate class and you have to create an object of singleton class (appDelegate) like this

AppDelegateClass  *appDelegate= [[UIApplication sharedApplication]delegate];

appDelegate.someObj=_theValueWhichYouToPass(/*here the value is integer*/).


//this assignment gives u this value anywhere you want through the object of appDelegate...

NSLog(@"%d",appDelegateObj.someObj);

You can use this value as you like..

              Hope this will help u very much ......
于 2013-05-20T11:51:25.900 に答える
1

プロパティを設定し、NextViewController で合成します

@property(nonatomic)NSInteger tagValue;

最初にタグを imageView に設定します

[ImgView setTag:randIdx]; 

Gesture rec を yourImageView に追加します

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
     tap.cancelsTouchesInView = YES;
     tap.numberOfTapsRequired = 2;
     tap.delegate = self;
     [ImgView addGestureRecognizer:tap];

次に、ダブル tapGesture で、 yourImage のタグ値を取得してから

// ハンドルメソッド

- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {
    UIImageView *imageView = (UIImageView *)[gestureRecognizer view];
    NSLog(@"Pass this tag=%d",image.tag);

    NextViewController *NVC=[[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
    NVC.tagValue=yourImageView.tag;
    [self.navigationController pushViewController:NVC animated:YES];

}
于 2013-05-20T06:01:27.847 に答える
1
     randIdx=arc4random()%[FrontsCards count];
     NSString *imageName=[FrontsCards objectAtIndex:randIdx];
     [ImgView setImage:[UIImage imageNamed:imageName]];
     ImgView.tag=randIdx;

     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
     tap.cancelsTouchesInView = YES;
     tap.numberOfTapsRequired = 2;
     tap.delegate = self;
     [ImgView addGestureRecognizer:tap];
     [tap release];

     ImgView.userInteractionEnabled = YES;

   // handle method
   - (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer { 
      UIImageView *imageView = (UIImageView *)[gestureRecognizer view];
       UIImage *image = [imageView image];
       NSLog(@"Pass this tag=%d",image.tag);
    }
于 2013-05-20T06:13:50.157 に答える
0

指定された init メソッドをオーバーライドすることで、 index を nextviewController に渡すことができます。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andIndex:(NSUInteger)index {

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if(self) {

    self.index = index;
}

return self;

}

または

- (id)initWithIndex:(NSUInteger)index {

self = [super init];

if(self) {

    self.index = index;
}

return self;

}

于 2013-05-20T06:02:23.123 に答える
0

@Rajneesh071 回答セットに加えて

randIdx=arc4random()%[FrontsCards count];
NSString *imageName=[FrontsCards objectAtIndex:randIdx];
[ImgView setImage:[UIImage imageNamed:imageName]];
//ADD THE TAG
[ImgView setTag:randIdx];
于 2013-05-20T06:09:59.043 に答える