我有一個視圖控制器,當它與完成dissming,我發佈一個notfication,並在其中包含在另一個視圖控制器子視圖,增加了作爲oberserve。但是,當它試圖執行後notificaiton梅索德,EXEC_BAD_ACCESS happend。怎麼了?該代碼是:NSNotificationCenter postNotificationName exec_badaccess
BrandListByIdViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSNumber *bid = self.brands[indexPath.row][@"id"];
[self dismissViewControllerAnimated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"SelectedBrandId" object:nil];
}];
}
SearchNewProduct.h
@interface SearchNewProduct : UIView
@end
SearchNewProduct.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didSelectedBrandId::) name:@"SelectedBrandId" object:nil];
}
}
- (void)didSelectedBrandId:(NSNotification *)notif{
NSLog(@"%s", __PRETTY_FUNCTION__);
}
即使我擺脫了用戶信息,還不能進入的。我在另一個新項目中創建了類似的情況,它工作正常。
'bid'不應該被釋放,因爲它是用戶信息字典的成員(保留有其價值並複製其鍵) – dreamlax
我試圖把postNotificationName方法駁回前完成。無論我把代碼放在哪裏。這個視圖控制器最終會解散。我試過委託,但它似乎不工作。委託方法將不會在uiview中執行。 –
修改了我的答案。我以爲你在處理兩個ViewController。代表屬於VC。你可以做的委託方法,讓擁有該視圖處理它,或嘗試上述修正答案VC。 –