我想执行其被解析XML动态创建不同的图像视图不同的动作。但imageviews在一个块中创建的,所以我将其与关联意见的标签是没有用的,因为他们都来到这是最后的标签相同。 任何帮助将不胜感激... :)如何知道我正在点击哪个ImageView?
代码: -
@class AppDelegate_iPhone,Litofinter,ParsingViewController;
@interface FirstViewController : UIViewController {
NSMutableArray *array;
NSString *logoString;
AppDelegate_iPhone *appDelegate;
ParsingViewController *obj;
UIScrollView *scrollView;
NSMutableArray *idArray;
// UIImageView *imgView;
}
@property (nonatomic,retain)UIScrollView *scrollView;
//@property (nonatomic,retain)UIImageView *imgView;
-(void)onTapImage;
@end
#import "FirstViewController.h"
#import "AppDelegate_iPhone.h"
#import "Litofinter.h"
#import "ParsingViewController.h"
@implementation FirstViewController
@synthesize scrollView;//,imgView;
-(id)init{
if(self == [super init]){
obj = [[ParsingViewController alloc] init];
array = [[NSArray alloc] initWithArray: obj.LogoMutableArray];
}
return self;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
int x=20,y=10;
int a=50,b=105;
appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,500, 460)];
scrollView.contentSize = CGSizeMake(320,800);
scrollView.showsVerticalScrollIndicator = YES;
for (Litofinter *lito in appDelegate.logoArray) {
NSString * urlString = [lito.cLogo stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL * imageURL = [NSURL URLWithString:urlString];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
[imgView setFrame:CGRectMake(x, y, 140, 90)];
imgView.userInteractionEnabled = YES;
imgView.multipleTouchEnabled = YES;
imgView.backgroundColor = [UIColor blueColor];
imgView.tag = lito.cId;
NSLog(@"Tag Id = %@",imgView.tag);
NSLog(@"Tag Id = %@",lito.cId);
[scrollView addSubview:imgView];
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapImage)];
[imgView addGestureRecognizer:tgr];
[tgr release];
//[imgView release];
UILabel *cName = [[UILabel alloc]initWithFrame:CGRectMake(a, b, 130, 20)];
cName.text = lito.cName;
[scrollView addSubview:cName];
//Do the rest of your operations here, don't forget to release the UIImageView
x = x + 150;
a = a + 140;
if(x >300)
{
y = y +140;
x = 20;
b = b +150;
a = 50;
}
// idArray = [[NSMutableArray alloc]init];
// [idArray addObject:lito.cId];
}
[self.view addSubview:scrollView];
}
-(void)onTapImage
{
NSLog(@"Tapped Image Id ======================== %@",view.tag);
//UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message from mAc" message:[NSString stringWithFormat:@"Tag Id : %@",imgView.tag] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
//[alert show];
}
- (void)dealloc {
[super dealloc];
[scrollView release];
}
@end
不要忘记,你也应该改变'UIGestureRecognizer 'init方法,因为选择器已经改变。 'UITapGestureRecognizer * TGR = [[UITapGestureRecognizer的alloc] initWithTarget:自动作:@selector(onTapImage :)];' –
;-)添加(在同一时间???) – EmptyStack
@空栈和菲利普萨比诺..... .Thanks很多朋友....ü[R非常适合我ATLEAST ...:d ..谢谢:)从我 – mAc