I have created a UITableViewcontroller and a UINavigationController in a TableController.m
with UITableviewCell set to say #"CellOne" #"CellTwo". Now I also created two other files
`ImageView1.m`
ImageView2.m
where if I click on CellOne I should be able to get the view placed on ImageView1.m, same applied to the ImageView2.m. How should I achieve this programmatically without using nib file?
override the touches event in ImageView1 and ImageView2.
Related
I have a custom UICollectionViewCell (let's call it MyCustomCell) that has a custom UITextField (let's call it MyCustomField) inside it that users can add text to. However, it seems no matter what I do, the tap inputs don't get from the MyCustomCell to its sub-view MyCustomField. Previously, I had this same arrangement, except MyCustomCell is a UITableViewCell, and that worked for some reason.
Right now I had to do a workaround, where whenever a cell is tapped, the cell sends a becomeFirstResponder() message to the textfield. However, this doesn't let the user tap on the "clear text" button inside the MyCustomField, nor does it let the user move the cursor around in the text field:
// function inside the MyCustomCell, called by the view controller
// whenever it thinks the user tapped on a cell:
func cellTapped()
{
// this is an instance of MyCustomField:
input.becomeFirstResponder();
}
Is there any way to "pass" the actual gesture to the MyCustomField (from either the MyCustomCell, or from the the view controller that manages them both)?
Update: this is what the view hierarchy looks like for the MyCustomCell (sub-class of UICollectionViewCell):
This may be of help to others who have similar issue: I believe #MultiColourPixel is correct in the comment above that there is a hidden "view" standing between the MyCustomField and MyCustomCell. What I did was:
Backed up the .xib and .swift files for the code for MyCustomCell and MyCustomField.
Delete the .xib and .swift files.
From the XCode menu, re-create the .swift file -- and make sure you check the "create XIB" as well when you create the .swift file / class that is subclass of the UICollectionViewCell.
Copy paste the old xib / swift contents into the new xib / swift.
It should work, without needing to explicitly send becomeFirstResponder() to the MyCustomField.
Problem Statement : I have a UIView Nib. Inside that Nib I have UICollectionView. I created Custom UICollectionViewCell and Assigned its class i.e. ServiceCollectionView Cell. I have 2 labels inside that UICollectionViewCell. Now When I try to Make an Outlet for those labels in custom class, I doesn't let me do that. I Have attached an image too. Anyone have an idea where the problem is ? Or What I am doing wrong. Any Help would be much appreciated.
Thanks
In case of adding a collection view/ table view in a UIView with separated .xib file, you should also create a separated .xib custom cell.
In your UIView Custom class, you should implement register(_:forCellWithReuseIdentifier:), for example:
// collectionView is the IBOutlet for the collection view that exists in the view .xib file
collectionView.register(UINib(nibName: "CustomCollectionViewCell", bundle: nil), forCellReuseIdentifier: "CustomCollectionViewCell")
And you will be good to go.
For some reason Xcode opens the interface (yourclass.swift (interface))and not the class. Restart Xcode and switch between automatic and manual did help me.
You create a collection View Cell nib file separately. Now you can give the outlet connection. error is not displayed.
I have a table view with one custom cell that I have already built and hooked up. When the user taps the add cell button I want it to add a different custom cell. I don't know where to start this process. Do I build it on the storyboard then hide it? Or what is the best means?
You should create all of your custom cells in the storyboard, and then implement UITableViewDataSource methods, where you return whatever cells you want.
Check out the documentation
I have a little problem, I want to add a function to two BarItems in my UINavigationBar, which is placed above the UITableView in a normal ViewController. I'm very new to programming so can you please give me the complete code that I need? The functions I want to have are:
An edit button so I can delete and change the data of a cell (title + subtitle)
An add button so I can add a new cell to my UITableView. Maybe also a function that points to another ViewController where I can type the data for Title and subtitle to save it afterwards.
Thanks!
For editing record:
You cannot get the cell that your planning to edit using button on UINavigationController, the buttons should be placed at the same cell on your UITableview to edit that specific cell. and in this way you need custom UITableviewcell.
For creating new record :
First link the button to your UIViewController class as Action.
You can append the array that your using to fill the UITableview and then call your UITableview like to refresh the data:
self.tableview.reloadData()
For presenting another UIViewController:
First drag new ViewController in your storyboard and link the button on the first ViewController into your new UIViewController and choose segue as "Show".
To save your data its a big topic you have either NSUserDefaults or CoreData so Google it.
Note : linking means by pressing ctrl-drag with mouse to your target.
Update :
Download your sample from here : https://yadi.sk/d/EJf610XWhkxDT
How does one in XCode XIB builder add a UIImageView to an existing MasterViewController that has a TableView and is based on NavigationController?
Scenario
For example if you create a new project based on MasterDetail in XCode 4
Then look at the MasterViewController.xib file - so want to add a UIImageView to this that could be used to overtake the screen up until a point after which the image view is made hidden to disappear.
I'm trying to drag a UIImageView onto the page, and putting it just able TableView in the Objects column, however this doesn't work. Doesn't even show the image.
So even just knowing how to drag-drop an image onto the MastViewController.xib such that it takes over the screen at startup would be a step forward (not sure if I need a view to encapsulate both the UIImageView and the TableView?)
Background
Want to have an intermediate image that the iPhone app shows as it starts up
Idea would be start up (static) image is show, then straight away go to MasterViewController which would show this same static image with an activity indicator on it
Then when (is a background thread) the data preparation is down, the UIImageView could be made non-visible
PS. Some additional notes:
Initially there is just a table view you see in MasterViewController.xib.
If I drag an imageview in at the same level as the TableView it doesn't appear.
If I create a new view in the XIB and put the tableview and uiimageview under this, I get an error when running "'-[UITableViewController loadView] loaded the "MasterViewController" nib but didn't get a UITableView.'"
Is there a view or just a table view in your xib? If you want both a image view and a table view in the same view controller, you should have an ordinary UIViewController and let in implement UITableViewDelegate and UITableViewDataSource protocols and add a table view and a image view to its view.
so solved by:
creating a top level "view" in the XIB
put the UITableView & the new UIImageView under this new view
but, had to change the interface line to inherit from UIViewController NOT UITableViewController
Just add Default.png in resource.