嗨,我正在使用 NSNotificationCenter defaultCenter 在我的应用程序中实现“喜欢”和“评论”功能。
//In Answer Table View
@implementation AnswerTableView
- (id)initWithParentController:(UIViewController *)pController andResourcePath:(NSString *)thisResourcePath {
....
// Notification to reload table when a comment is submitted
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTable)
name:@"Comment Submitted"
object:nil];
// Notification to reload table when an answer is liked
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTable)
name:@"Answer Liked"
object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
//In custom button implementation - THIS BUTTON IS CREATED IN EVERY CELL OF THE TABLEVIEW
@implementation UICustomButton
-(id)initWithButtonType:(NSString *)type {
self = [super init];
if (self) {
//Initialization done here
}
return self;
}
- (void)buttonPressed {
if ([btnType isEqualToString:@"like"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"Answer Liked" object:nil];
}
else if ([btnType isEqualToString:@"comment"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"Comment Submitted" object:nil];
}
}
但是,我意识到在使用这些功能一段时间后,表重新加载的响应速度越来越慢(到了崩溃的地步)。
我是否错过了实现中的任何内容,即解除分配等