我正在以编程方式创建一个按钮并添加一个目标。当我运行按钮时几秒钟没有响应(如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 ");
...
}