1

我在我的视图中有一个自定义表名 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 时,发生了一些事情并且没有调用 touch end 方法,所以 sublable 不会像这样从视图中删除。像这样......在此处输入图像描述

所以我做错了什么这个......是的,我在桌面触摸上调用触摸事件,你会注意到的。请帮助我解决这个问题...在此先感谢。

4

0 回答 0