retain-cycle

Is weak self needed for table view cell button closure

时光怂恿深爱的人放手 提交于 2021-02-05 08:56:31
问题 In trying to avoid retain cycles, would using [weak self] in in a UITableViewCell button action be necessary? Example: in ViewController's cellForRow cell.buttonAction = { (cell) [weak self] in self.someFunction() } in TableViewCell class var buttonAction: ((UITableViewCell) -> Void)? @IBAction func buttonPressed(_ sender: Any) { buttonAction?(self) } 回答1: The key line to think about is: var buttonAction: ((UITableViewCell) -> Void)? You are offering to store a function long-term in an

Is weak self needed for table view cell button closure

吃可爱长大的小学妹 提交于 2021-01-28 11:34:51
问题 In trying to avoid retain cycles, would using [weak self] in in a UITableViewCell button action be necessary? Example: in ViewController's cellForRow cell.buttonAction = { (cell) [weak self] in self.someFunction() } in TableViewCell class var buttonAction: ((UITableViewCell) -> Void)? @IBAction func buttonPressed(_ sender: Any) { buttonAction?(self) } 回答1: The key line to think about is: var buttonAction: ((UITableViewCell) -> Void)? You are offering to store a function long-term in an

How to get rid of retain cycle with collectionview

安稳与你 提交于 2020-06-13 09:18:23
问题 I am having trouble destroying viewcontrollers due what I believe to be a retain cycle between a collectionview and the viewcontroller. I tried making the collectionview a weak variable but I am now getting nil whenever I trying to add the collectionview to the viewcontroller. If there is another route to try rather than making the collectionview weak I'm open to that as well. weak var table = UICollectionView(frame: CGRect(x: 0, y: 0, width: 0, height: 0), collectionViewLayout:

How to get rid of retain cycle with collectionview

為{幸葍}努か 提交于 2020-06-13 09:18:15
问题 I am having trouble destroying viewcontrollers due what I believe to be a retain cycle between a collectionview and the viewcontroller. I tried making the collectionview a weak variable but I am now getting nil whenever I trying to add the collectionview to the viewcontroller. If there is another route to try rather than making the collectionview weak I'm open to that as well. weak var table = UICollectionView(frame: CGRect(x: 0, y: 0, width: 0, height: 0), collectionViewLayout:

Strongly in this block is likely to lead to a retain cycle [duplicate]

流过昼夜 提交于 2020-05-01 07:23:27
问题 This question already has answers here : Fix warning “Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code (7 answers) Closed 5 years ago . I create the custom cell with the activity indicator view With using the SDWebImage I hidden the activity indicator when the image is downloaded [customCell.userPhotoImageView setImageWithURL:[NSURL URLWithString:[[thisNotify user]imageURL]] placeholderImage:nil completed:^ (UIImage *image, NSError *error,

Memory is not released during perform batch updates in CollectionView

£可爱£侵袭症+ 提交于 2020-01-25 09:06:01
问题 I've been working on a project of using two UICollectionView 's I have on that is the MainViewController with full screen cells that scroll horizontally and one that sits on that full screen cell and scrolls vertically. I have a functionality that adds as well as deletes cells. When a user taps and one of the pages of the MainViewController is deleted using the code below the memory that grew as cells were added is still being retained. Is there something Im doing wrong. All of my delegates

Memory is not released during perform batch updates in CollectionView

你说的曾经没有我的故事 提交于 2020-01-25 09:05:30
问题 I've been working on a project of using two UICollectionView 's I have on that is the MainViewController with full screen cells that scroll horizontally and one that sits on that full screen cell and scrolls vertically. I have a functionality that adds as well as deletes cells. When a user taps and one of the pages of the MainViewController is deleted using the code below the memory that grew as cells were added is still being retained. Is there something Im doing wrong. All of my delegates

blocks, self, retain cycles

二次信任 提交于 2020-01-22 06:01:05
问题 I'm having a bit of trouble getting my head around referencing self within a block, and not creating a retain cycle. Can you let me know if my understanding is correct: If I ever reference self within a block, it will create a retain cycle, and instead I should be creating a weak reference to self outside of the block and then using that weak reference inside the block? Thanks! 回答1: Yes, that is correct, with a few exceptions: A retain cycle only happens if self ends up retaining the block

Using weak self in dispatch_async function

只愿长相守 提交于 2020-01-18 11:08:08
问题 I read a lot of posts about using __weak self inside dispatch_async , and now I am a litle bit confused. if I have : self.myQueue = dispatch_queue_create("com.biview.core_data", NULL); dispatch_async(self.myQueue, ^(void){ if (!self.var1) { self.var1 = ...; } dispatch_async(dispatch_get_main_queue(), ^(void) { if ([self.var2 superview]) { [self.var2 removeFromSuperview]; } [self.Label setText:text]; }); }); do I need to use __weak self . Because I read that in some cases dispatch_async not

Back button not being called in TabbarCoordinator in horizontal flow iOS 12

血红的双手。 提交于 2020-01-16 10:11:48
问题 Coordinator pattern is an old topic with many libraries trying to solve it and I am learning it in simple example app. My current set up is 3 rootViewControlers: LoadingStateCoordinator , WelcomeCoordinator , TabBarCoordinator but missing connection between UIKit and coordinators. I am trying to implement it with a UINavigationController but the button is not being called. I need a way to connect to back button and a reusable coordinator that I could push to and dellocate accordingly (that is