logo
down
shadow

instantiate a storyboard from a button press inside a collection view cell


instantiate a storyboard from a button press inside a collection view cell

Content Index :

instantiate a storyboard from a button press inside a collection view cell
Tag : ios , By : Chris Tattum
Date : November 29 2020, 04:01 AM

will help you I'm trying to instantiate a storyboard from a button press inside a collection view cell but am coming across errors: , 1- You don't have a class named InputViewController
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "InputViewController") as! InputViewController 
present(vc, animated: false) 
UIStoryboard(name: "Main", bundle: nil)
self.storyboard
class sampleCell: UICollectionViewCell {
  weak var delegate:CurrentController?
}
let cell = /////
cell.delegate = self
func goToInput() {

    let vc = self.storyboard!.instantiateViewController(withIdentifier: "InputViewController") as! InputViewController//error: Use of undeclared type "InputViewController" 
    present(vc, animated: false) 

}
@IBAction func infoButtonPressed(_ sender: Any) {
  delegate?.goToInput()
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to calculate collection view cell height using cell defined in storyboard?


Tag : ios , By : user103892
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Yes, you can do that. I usually create a property for my cell, and instantiate it in viewDidLoad (using dequeueReusableCellWithReuseIdentifier:forIndexPath:), then use that cell for doing size calculations in collectionView:layout:sizeForItemAtIndexPath:.
-(void)viewDidLoad {
    [super viewDidLoad];
    self.cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"RDCell" forIndexPath:nil];
    [self.collectionView reloadData];
}

How to Display button in Collection view cell when user uses a Long press gesture.


Tag : ios , By : Mare Astra
Date : March 29 2020, 07:55 AM
it fixes the issue well i have been struck with this past two days and havent found a solution any where. I am working with collection where i create a button dynamically on each collection cell and hided it, When User uses a long Press gesture the Button should be displayed in each and every cell. How should i implement this. Any ideas are greatly thankful. , How about you create a BOOL flag say:
@interface MyViewController
{
    BOOL shouldDisplayButton;
}

@end
-(void)viewDidLoad
{
    [super viewDidLoad];
    ...

    UILongPressGestureRecognizer *longPress = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];

    ...

    [self.myCollectionView addGestureRecognizer:longPress];
}

-(void)handleLongPress:(UILongPressGestureRecognizer *)longPressGesture
{
    // -------------------------------------------------------------------
    // we only want to trigger this if the user let go of the long press
    // otherwise, the long press will continuously execute this block
    // -------------------------------------------------------------------
    if(longPressGesture.state == UIGestureRecognizerStateEnded)
    {
        // ----------------------------------------------------------------
        // This basically toggles the boolean flag on and off then reload
        // your collection view. See your collectionView cellForRowAtIndex
        // where you enable the button based on the value of this boolean.
        // ----------------------------------------------------------------
        if(shouldDisplayButton)
        {
            shouldDisplayButton = NO;
        }
        else
        {
            shouldDisplayButton = YES;
        }

        [self.myCollectionView reloadData];
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{
    ....

    button=[[UIButton alloc]init];
    [button setFrame:CGRectMake(5,5,10,23)];
    [button setTitle:@"X" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

    [myCell addSubview:button];


    // ---------------------------------------------------------------------
    // Here you only hide your button if the BOOL flag is NO, otherwise,
    // you show your button.
    // ---------------------------------------------------------------------
    if(shouldDisplayButton)
    {
        [button setHidden:NO];
    }
    else
    {
        [button setHidden:YES];
    }
}

Fill width of button inside collection view cell


Tag : ios , By : mux
Date : March 29 2020, 07:55 AM
it fixes the issue First, delete the width constraint (if you have one). Then pin the button to the edges and set constraints:

Transfer data from table view cell inside a collection view cell, to another collection view cell [with picture!]


Tag : ios , By : Sebastian Gift
Date : March 29 2020, 07:55 AM
I wish this helpful for you Your table view has a dependency on the parent collection view cell. That means you need to pass a reference of the collection view cell to the table view on instantiation. I'd make a protocol.
protocol myTableViewCellDelegate {
  func updateMyCollectionViewCell
}

extension myCollectionViewCell: myTableViewCellDelegate {
  func updateMyCollectionViewCell {
    // update whatever you need to here
  }
}

extension myCollectionTableViewDelegate: UITableViewDelegate {
  // ...
  func collectionView(_ collectionView: UICollectionView, 
                      willDisplay cell: UICollectionViewCell, 
                      forItemAt indexPath: IndexPath) {
    // instantiate table view
    // pass self to tableview *as weak reference*
    myTableView.customDelegate = self
  }
  //...
}

extension myTableViewDelegate: UITableViewDelegate {
  //...
  func tableView(_ tableView: UITableView, 
                 didSelectRowAt indexPath: IndexPath) {
    // instantiate table view cell
    // assuming you're not using custom cell class
    tableCell.updateMyCollectionViewCell()

    // if you are using custom cell class then the tableViewDelegate
    // will need to pass collectionView reference on to the cells
  }
}

How to delete a indiviudal collection view cell via button inside that cell using a tag


Tag : swift , By : user86493
Date : March 29 2020, 07:55 AM
it fixes the issue You need to delete the item from the dataSource/core data and then reload the collection view.
@objc func elete(_ sender:UIButton){
    itemName.remove(at: sender.tag) // this removes from array, but you should also remove from core data.

    collectionView.reloadData()
}
Related Posts Related QUESTIONS :
  • How to make a reference to a uid stored in Firestore?
  • How do you initialize/use UITableViewCells with CellStyle = .value1 programmatically?
  • How to know if Apple has received our appeal/how long does it take Apple to respond?
  • Select new item added to SwiftUI List
  • What is the correct length: argument to provide to NSRange for NSRegularExpression using a (Swift) String?
  • I am trying to delete data from database, but sometime data is deleted and sometime data is not deleted
  • How to get slider value with subview rotation angle
  • Can't pass custom UINavigationBar / UIToolbar to UINavigationController because they don't conform to AnyClass
  • Grab SELECTED text on UITextView
  • Clever ways to better test GPS code using only the iPhone simulator?
  • Remove app before simulator or device is lunched from Xcode
  • Auto Layout constraints for container view inside UITableView header broken for different devices
  • iPhone restarts after API call
  • What is the shortcut / How do I create function after writing it's usage in Xcode
  • Convert apple time stamp to Unix time
  • No podspec found for `React-fishhook`
  • How to test touch dialog and perform real in-app purchase?
  • Compiling Metal shaders from source on iOS 13 Simulator gives PCH error
  • conan error:I need to cross build packages for os:iOS with my Macos, but when the first package was done, it broke my cp
  • Update calendar 'start of week' from phones system calendar
  • Xcode is showing some warnings
  • How to remove the default Navigation Bar space in SwiftUI NavigiationView
  • Having trouble integrating multiple pickerviews in the same view
  • SCNNode not in SCNView hierarchy, still showing & getting touches & physics
  • How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension?
  • NSCoding decodeObject always nil
  • Passing data in a segmented Controller?
  • Facing issue in Siri Integration with custom intents
  • ARKit3 Hardware Requirement Clarification
  • ARKit3 How to use TrueDepth camera for face tracking and face meshes of other people?
  • How to discriminate while decoding using Codable Protocol in Swift?
  • 'IPA processing failed' while distributing build in Xcode Beta
  • How to debug a crash which happened when come back from background
  • Synchronising old data with NSPersistentCloudKitContainer
  • iOS app opened from web app with url redirects to Appstore
  • How to change the color of seperator in tableView?
  • Is there a better way to watch for a key-value change?
  • How to make UIBezierPath to fill from the center
  • Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:
  • How to scan non LE devices using Swift?
  • Unable to infer closure type in the current context in SwiftUI
  • What is the best way to write common code and use it entire project
  • UISegmentedControl inside UIStackView, segments text not centered - iOS 13
  • Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"
  • SwiftUI How to push to next screen when tapping on Button
  • 'NSApp' is unavailable in UIKit for Mac: How to embed Mac only framework in iOS app on macOS?
  • UserDefaults Binding with Toggle in SwiftUI
  • How to create a color with an alpha value using SwiftUI?
  • SwiftUI creates destination views before the user navigates to them
  • Streaming video from https with AVPlayer causes initial delay
  • Tap Action not working when Color is clear SwiftUI
  • SwiftUI NavigationButton: How to navigate to different destinations
  • Supported default light/dark mode colors for Color vs UIColor
  • XCUITest wait for a cell with a specific static text inside it
  • Not able to enable Development mode on iOS 13
  • How to hide the home indicator with SwiftUI?
  • How to write if condition with using label text (Int) values
  • Swift Cannot use instance member within property initializer
  • Issue while getting the frame of the keyboard
  • dynamicMemberLoookup ExpressibleByStringLiteral parameter swift
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com