Iphone 将数组索引传输到下一个控制器
我有一个数组。从该数组获取图像时,我想将数组索引传输到下一个方法。如何执行此操作 我的代码:-Iphone 将数组索引传输到下一个控制器,iphone,ios,objective-c,Iphone,Ios,Objective C,我有一个数组。从该数组获取图像时,我想将数组索引传输到下一个方法。如何执行此操作 我的代码:- FrontsCards =[[NSMutableArray alloc]initWithCapacity:13]; [FrontsCards insertObject:@"cloub1.png" atIndex:0]; [FrontsCards insertObject:@"cloub2.png" atIndex:1]; [FrontsCards insertObject:@"
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
我可以怎样做呢?提前谢谢。设置属性,并在您的下一个视图控制器中合成它
@属性(非原子)NSInteger标记值代码>
首先将标记设置为imageView
[ImgView setTag:randIdx];
将手势记录添加到ImageView
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 2;
tap.delegate = self;
[ImgView addGestureRecognizer:tap];
然后在你的双击手势上,得到你的图像的标签值
//处理方法
- (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];
}
设置属性,并在下一个ViewController中合成它
@属性(非原子)NSInteger标记值代码>
首先将标记设置为imageView
[ImgView setTag:randIdx];
将手势记录添加到ImageView
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 2;
tap.delegate = self;
[ImgView addGestureRecognizer:tap];
然后在你的双击手势上,得到你的图像的标签值
//处理方法
- (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];
}
您可以通过覆盖给定的init方法将索引传递给nextviewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andIndex:(NSUInteger)index {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self) {
self.index = index;
}
return self;
}
或
}您可以通过覆盖给定的init方法将索引传递给nextviewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andIndex:(NSUInteger)index {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self) {
self.index = index;
}
return self;
}
或
}除了@Rajneesh071答案集
randIdx=arc4random()%[FrontsCards count];
NSString *imageName=[FrontsCards objectAtIndex:randIdx];
[ImgView setImage:[UIImage imageNamed:imageName]];
//ADD THE TAG
[ImgView setTag:randIdx];
除了@Rajneesh071答案集
randIdx=arc4random()%[FrontsCards count];
NSString *imageName=[FrontsCards objectAtIndex:randIdx];
[ImgView setImage:[UIImage imageNamed:imageName]];
//ADD THE TAG
[ImgView setTag:randIdx];
通过在appDelegate
中创建@property
,您可以将任何类型的数据传递到应用程序中的任何位置。
例如,如果要将任何整数数据传递给某个视图控制器,则必须在appDelegate
---
@synthesize someObj;
在appDelegate.h
----
在appDelegate.m
-----
然后你可以通过导入appDelegate类在你想要的地方访问这个对象,你必须像这样创建一个singleton类(appDelegate)的对象
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);
您可以随意使用此值
Hope this will help u very much ......
通过在appDelegate
中创建@property
,您可以将任何类型的数据传递到应用程序中的任何位置。
例如,如果要将任何整数数据传递给某个视图控制器,则必须在appDelegate
---
@synthesize someObj;
在appDelegate.h
----
在appDelegate.m
-----
然后你可以通过导入appDelegate类在你想要的地方访问这个对象,你必须像这样创建一个singleton类(appDelegate)的对象
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);
您可以随意使用此值
Hope this will help u very much ......
只需为所有imageview设置标记,并在用户选项卡获取标记并发送到下一个viewcontrolleri时添加UITAbgestureOnignizerimageview@JitendraDeore为什么您不能使用randIdx
并将此值传递给其他视图控制器。我不完全确定您要的是什么。但是,这是向数组添加对象的最长方法。您可以使用addObject:(仅添加到数组末尾)、initWithObjects:(将使用对象列表初始化数组)或使用新的@[]创建数组的语法。我想在用户开始新建时随机显示所有图像,这就是我使用randIdx的原因。只需为所有imageview设置标记,并在用户选项卡获得标记并发送到下一个viewcontrolleri时添加UITAbgestureOnignizerimageview@JitendraDeore为什么不能使用randIdx
并将此值传递给其他视图控制员,我不太清楚你要什么。但是,这是向数组添加对象的最长方法。您可以使用addObject:(仅添加到数组末尾)、initWithObjects:(将使用对象列表初始化数组)或使用新的@[]创建数组的语法。我想在用户开始新建时随机显示所有图像,这就是我使用randIdx的原因。我想如果用户dobble点击特定图像,我想得到该图像值–Rajneesh071如果用户点击cloub10.png图像,我想得到9值,这是我的要求。根据您的问题,请重新理解我的要求,您正在数组的9索引处插入cloub10图像,我们还将tagValue设置为图像视图的索引(例如9),然后得到这个gegValue.no,所有图像都会随机变化,那么如果用户dobble点击特定图像,我如何得到我想要的图像索引值?我想要那个图像值–Rajneesh071如果用户点击cloub10.png图像,我想要我要求的9值。根据你的问题,你不需要重新理解我的要求,您正在数组的9索引处插入cloub10图像,我们还将tagValue设置为图像视图的索引(例如9),然后获取这个gegValue.no,所有图像都会随机更改,那么如何获取图像索引值我想要用户double tapped value我想要用户double tapped value我想要图像的double tapped value这意味着什么,你想要UIImage对象,imageName或你点击的imageIndex?@Jitendra:Mate当你有索引时,为什么你不能从FrontCards数组中获取图像值。我想要用户Double点击的imageIndex。我想要ImageDouble点击的值这意味着什么,你想要UIImage对象,imageName或你点击的imageIndex?@Jitendra:Mate当你有索引时,为什么你不能从FrontCards数组中获取图像值。我想要用户Double点击的imageIndex。