こんにちは、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];
}
}
しかし、これらの機能をしばらく使っていると、テーブルのリロードの応答速度が遅くなる (クラッシュする) ことに気付きました。
実装で何かを見逃していませんか。つまり、割り当て解除などです。