0

我正在以编程方式创建一个按钮并添加一个目标。当我运行该按钮几秒钟(如 5 或 7 秒)没有响应,然后它开始工作。我不明白为什么会这样。我所有的网络连接都在后台线程上,并且在所有网络内容完成之后创建按钮,并且在任何时候都不会锁定其余的 UI。它似乎只是一个按钮。对可能发生的事情有任何想法吗?代码很标准,我只是觉得每个帖子都应该有一点代码。

-(void)viewDidLoad{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(getComments)
                                                 name:@"Update"
                                               object:nil];
...
}
-(void)getComments{
    WrapperView *wrapper = (WrapperView*)self.parentViewController;
    [Comment getCommentsForLunchPk:wrapper.lunch.pk WithCompletionBlock:^(bool success, NSArray *cmnts) {
        if(success){
            comments = cmnts;
            [self updateCommentView];
        }
    }];
}
-(void)updateComments{
   ...
   UIButton *delete = [[UIButton alloc] initWithFrame:CGRectMake(246, 4, 55, 55)];
   delete.tag = comment.pk;
   [delete addTarget:self action:@selector(deleteComment:) forControlEvents:UIControlEventTouchUpInside];
   [delete setTitle:@"x" forState:UIControlStateNormal];
   [commentView addSubview:delete];
   ...
}
-(void)deleteComment:(UIButton*) button{
    NSLog(@"delete ");
    ...
}
4

0 回答 0