I want to implement the Tab View like Apple has in their Apple Maps when you select a location and tap on the more details to reviews additional information about that location.
What would be the best way to implement this or how do you think Apple has implemented it. I know each tab view has a Table View inside each. Also for the Photos tab how do you think they implemented the content inside that tab. Was it using UICollectionView or a table view with a custom cell that has 4 photos in each cell row?
It looks like they're using one UITableView and on UISegmentedControl. With this combination every time the user selects and index on the segmented control, it changes a condition in the table's datasource and reloads the data. Here's an example of what something like that could look like to conditionally change the number of rows in the table
- (IBAction)segmentValueDidChange:(UISegmentedControl *)sender
{
NSLog(#"%d",sender.selectedSegmentIndex);
[self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.segment.selectedSegmentIndex == 0) {
return 5;
}
return 10;
}
Related
I am writing an image gallery application that has multiple categories in which the user can view photos. On one of the menus, there are three UIButtons that list the categories of photos: 1970s, 1980s, 1990s.
When the user taps on "1970s", it segues into a Table View where there is an array of photos and labels. Each Table cell has its own photo and corresponding label dictating the date and location of the photo. When the user taps on a cell, it leads to a UIImage view and a scroll view where the image can be viewed fullscreen and zoomed/panned. There is also a little popover view on the UIImage view that can be displayed via a button.
The problem I'm having is that the Table view, Image view, and popover view take up three Storyboard "controllers". I want to replicate this table view, fullscreen image view, and popover view across many different categories (UIButtons) I have all over the app.
Is there a way to repopulate a Table View depending on which UIButton is pressed?
Thanks for the help! I am in Swift 3 and using Xcode.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return dataArray.count;
}
- (void) 1970Action{
dataArray = 1970ImagesArray;
[self.tableView reloadData];
}
- (void) 1980Action{
dataArray = 1980ImagesArray;
[self.tableView reloadData];
}
- (void) 1990Action{
dataArray = 1990ImagesArray;
[self.tableView reloadData];
}
I have implemented a section index, letters at the right of the table view that allow quickly jumping to a section, in my app. I would like to disable user interaction with that section index in some situations, but there is no property on UITableView that allows directly accessing the section index.
How can I disable user interaction for section indexes?
I have disabled interaction with the table itself so that you cannot scroll or tap any cell, but this still allows interacting with the section indexes, so it will scroll to each section upon tapping a section icon.
self.tableView.userInteractionEnabled = NO;
If it's not possible to disable interaction with the section index itself, is there a way to prevent changing the scroll position of the table? That's exactly what I wanted to obtain.
As an alternative, if you wish to allow scrolling - so users can see what's there - but prevent them from making selections, etc. you can do the following instead:
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.tableViewIsDidabled)
return nil;
else
return indexPath;
}
and, setting the sectionForSectionIndexTitle to nil.
I found a solution.
Keep a BOOL to know when the section indexes should be disabled.
Then in tableView:sectionForSectionIndexTitle:atIndex: just return -1 to prevent scrolling when tapping indexes.
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if (self.tableViewIsDisabled) {
return -1;
}
...
}
UITableView *tab;
mm to disable scroll..
tab.scrollEnabled = NO;
if you wanna use it in certain situations..
you can try with a powerful..
if(...)
tab.scrollEnabled = NO;
I'm trying to use PFQueryTableViewController but I can't get to minimise it so it won't take over the entire screen (top to bottom).
My main goal is to place in a tab controller so one of the tabs will display a table - but even after adding a title the table is still under the title and not just below it (first record is hidden...)
Is there a way to manipulate it a bit? All the videos I could find ended up with a full screen table - which is cool to have in 2 minutes but it's not usable at all.
Thanks!
By using:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == self.objects.count) {
return 0.0f;
}
return 65.0f;
}
I was able to arrange the table layout.
I want to set up a UISearchDisplayController such that after a cell is selected from the search results, the search display controller is dismissed and the table view scrolls to the selected cell. Here's my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
[self.searchDisplayController setActive:NO];
// scroll to selected cell in table view here
}
}
I know the method I need to use is:
scrollToRowAtIndexPath:atScrollPosition:animated:
However, this method needs an index path from the main table view, not the search results table view. How can I get this index path?
What does your datasource look like? Perhaps you can query the datasource based on what was selected in the search results to get the cell's index.
Sounds like a strange user interaction not knowing what you're doing though. Normally searching and then selecting will take you to that record's details or select it as an option or something.
I have a UITableView where I want to be able to insert rows via the Insertion Control (green plus icon). (I originally had this working with the Add control on the navigation bar, but with 'back', 'add', and 'edit' controls I felt the navigation bar was a bit cluttered).
I got this working, but I don't like the way this interacts with the reorder control. My table only has one section; the insertion row will always be shown as the last row in the table, and it should not be reorderable.
I implemented canMoveRowAtIndexPath: to return false for the insertion control row, but this is only a partial solution. That removed the ability to drag the insertion row. However, nothing prevents a user from selecting a movable row and dragging it beneath the insertion controller row. (And if allowed, this crashes the app).
The workaround I've implemented is to check the to location in moveRowAtIndexPath:toIndexPath. If the destination location is below the insertion row, I do not perform the move, and I call [tableView reloadData] to redraw the previous table state. This works, but the appearance is clunky -- the row just snaps back to its previous position with no indication why.
Is this the correct behavior here -- or is there a more elegant solution? Ideally, I'd like the user to not be able to drag the row to an illegal location in the first place, but I'm not sure there is any mechanism to prevent it.
You need to implement the tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: delegate method. The implementation should return an appropriate index path based on whether the row can be targeted to the desired row or not.
Here's the implementation:
// Don't allow dragging any moveable row below the insertion control
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath: (NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
int proposedRow = proposedDestinationIndexPath.row;
int maxRow = [[[SADeckStore sharedStore] allDecks] count] - 1;
if (proposedRow < maxRow)
return proposedDestinationIndexPath;
else
return [NSIndexPath indexPathForRow:maxRow inSection:[proposedDestinationIndexPath section]];
}