【发布时间】:2014-08-05 06:35:17
【问题描述】:
好的,这是一个完全不在意的问题。我有一个视图控制器,我在其上添加了UITapGestureRecognizer。当用户点击 View 时,自定义 UIView 会添加到该点击位置。这是UITapGestureRecogniser 的代码:
-(IBAction)singleTap_Detected:(UITapGestureRecognizer *)recognizer
{
CGPoint tapPoint = [recognizer locationInView:self.view];
customView=[CustomPointUIView addCustomView];
[customView.pointSelectionButton addTarget:self action:@selector(addInfoAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customView];
customView.layer.position=CGPointMake(tapPoint.x,tapPoint.y);
[customViewsArray addObject:[NSValue valueWithCGPoint:tapPoint]];
NSManagedObjectContext *context = [self.circuit managedObjectContext];
// if there isn't an Point object, create and configure one
self.point = [NSEntityDescription insertNewObjectForEntityForName:@"PointDetail"
inManagedObjectContext:context];
[self.circuit addPointObject:self.point];
NSString *pointPosition=NSStringFromCGPoint(tapPoint);
self.point.position=pointPosition;
NSError *error = nil;
if (![context save:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
我还将点击位置保存在Core Data 中。现在的问题是我无法为视图控制器上添加的每个自定义UIView 设置标签。如图所示,每个自定义UIView 都有一个按钮。单击该Button,视图将导航到另一个视图。现在我需要为每个视图设置标签。这怎么可能 ?我不知道我是否能够清除我的概念但我会发自内心的感谢。所以,请给我一个解决方案。我是 iPhone 新手。
【问题讨论】:
-
不就是
customView.tag = tagValue;吗? -
@Droppy 是的,但是 tagValue 应该是什么。我需要它随着每个新添加的
CustomView而增加。 -
所以,你必须在你的类中添加 ivar
NSInteger tagValue并在customView.tag = tagValue; tagValue++之后每次增加它
标签: ios objective-c iphone core-data uitapgesturerecognizer