我的视图中有一个自定义表名tbltask,触摸开始和触摸移动方法我动态创建标签。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
self.scrollEnabled=NO;
CGPoint point = [[touches anyObject] locationInView:[self superview]];
CGPoint pointtask=[[touches anyObject] locationInView:self];
NSIndexPath *indexPath = [self indexPathForRowAtPoint:pointtask];
rowid=indexPath.row;
app.sublable=[[UILabel alloc] initWithFrame:CGRectMake((point.x)-145, (point.y)-50, 300, 40)];
app.sublable.textAlignment=UITextAlignmentRight;
messagedrag=[app.arraddtask objectAtIndex:rowid];
app.sublable.text=[NSString stringWithFormat:@" %@",messagedrag.msgsubject];
app.sublable.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"black.png"]];
app.sublable.layer.cornerRadius=8.0;
app.sublable.layer.borderWidth=4;
app.sublable.layer.borderColor=[[UIColor lightGrayColor] CGColor];
app.sublable.textColor=[UIColor whiteColor];
UIFont *f = [UIFont fontWithName:@"Verdana-Bold" size:16];
app.sublable.font = f;
[app.sublable setTextAlignment:UITextAlignmentLeft];
[self.superview addSubview:app.sublable];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
if(app.sublable!=nil)
{
[app.sublable removeFromSuperview];
}
CGPoint point = [[touches anyObject] locationInView:[self superview]];
NSIndexPath *indexPath = [self indexPathForRowAtPoint:point];
NSLog(@"............super %f",[self superview].frame.origin.y);
app.sublable=[[UILabel alloc] initWithFrame:CGRectMake((point.x)-145, (point.y)-50, 300, 40)];
app.sublable.textAlignment=UITextAlignmentRight;
messagedrag=[app.arraddtask objectAtIndex:rowid];
app.sublable.text=[NSString stringWithFormat:@" %@",messagedrag.msgsubject];
app.sublable.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"black.png"]];
app.sublable.layer.borderWidth=4;
app.sublable.layer.borderColor=[[UIColor lightGrayColor] CGColor];
app.sublable.layer.cornerRadius=8.0;
app.sublable.textColor=[UIColor whiteColor];
UIFont *f = [UIFont fontWithName:@"Verdana-Bold" size:16];
app.sublable.font = f;
[app.sublable setTextAlignment:UITextAlignmentLeft];
[self.superview addSubview:app.sublable];
}
导致了这一点。
所以当我触摸tbltask touchBegan方法开始工作并创建一个带有主题的标签时会在superview中写入,这是主视图,其中tbltask就在那里你可以看到。(底部是表任务)
现在当我调用touchesEnded方法::
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
//<my stuff>
[super touchesEnded:touches withEvent:event];
NSString *taskname=[[NSString alloc] init];
self.scrollEnabled=YES;
if(app.sublable!=nil)
{
taskname=app.sublable.text;
[app.sublable removeFromSuperview];
}
[taskdelegate droptask:self strtask:taskname];
}
这个问题放在上面
它运行正常。但是当我从左到右或从右到左触摸tbltask时发生了一些事情,并且没有调用触摸结束方法,因此不会从视图中移除sublable。就像这样......
我在这做错了什么......
是的,我会在桌面触摸时调用触摸事件,您会注意到。
请帮我解决这个问题......
在此先感谢。