I would like to use the clean and simple type of UITableView designs that Apple uses on their iTunes Connect app for iPad.
Looking at the Markets tab.
The top TV uses the 1st row for column names, the following rows hold the data that corresponds with those columns.
When you scroll up the top row (the column labels) stay put as you'd expect, like the way a typical spread sheet is set up.
How is that being accomplished? I cant get that functionality using the available styles.
I'm also interested by the header and surrounding rounded rectangle of the bottom TV, is that accomplished with graphics in a UIImageView?
You need to use sections and rows methods. The sections create your headers that float as you scroll through your table and the rows contain the records that the user can select. There are several different styles. Here is a good explanation of tableview styles. If you need to create more complex tables what you need to do is create a collection.
Below is sample are the method used for creating sections and rows.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 10; //you could take the count of records in an NSarray/NSdictionary here instead
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5; //you could take the count of records in an NSarray/NSdictionary here instead
}
Related
I have a UITableView with 6 rows. Each row contains a single UICollectionView. Each collection view contains a single section with 10-15 cells. One view controller is the datasource and delegate for both the table view and the collection view.
I would like to address some performance issues when scrolling the tableview. Whenever a new section comes into view, there is a small pause while the collection view is created and filled. Since I have a fixed number of cells (< 100) and they are almost static (they are initially loaded from a web API but the data will change only a couple of times a week), I would like to pre-build each of the collection view cells in advance. I would prefer the user waits an extra half-second on launch than encounters jerky scrolling.
To accomplish this, I have updated my collectionView: cellForItemAtIndexPath: to check a dictionary of cells I am maintaining. It looks for a key composited from the collection view index and the indexPath for the cell. If the key exists, the corresponding object is returned. If none is found, the cell is built and also added to the dictionary. This step effectively prevents cells from being un-loaded and recycled, at the expense of using more memory.
But on launch, I still need to run this once for each cell to pre-populate the dictionary. I iterate over each table view cell, find the collection view, and call
[self collectionView:collectionView cellForItemAtIndexPath:indexPath];
This is almost enough. The cells are being created and stored in the dictionary, and when I scroll to a new collection view, I see that they are being pulled from the dictionary and are displayed. But all of the cells, and all of their contents, are shoved up in the top-left corner at {0,0}.
Some logging tells me that at the time the cells are created, the frame of the collection view is {{0, 0}, {0, 0}}. I assume this is why none of my layout is being applied?
How can I resolve this?
(Would also be interested in any general comments on my pre-loading implementation).
I resolved this by calling [cell layoutIfNeeded] on the UITableViewCell (not the collection view). A more thorough explanation is welcomed.
I'm new to titanium and I,m trying to build some prototypes based on wireframes. Below is the wireframe that I'm trying to build as prototype.
What you see is a list of restaurants fetched from google places api. The main functionality here is the black strip which will be at a fixed position and holds the details of rating and reviews on a particular restaurant which is underneath it.
So if I scroll through the restaurants the black strip should get the rating details of that particular restaurant which is underneath it.
So far I was able to crawl the restaurants data from google places api into row of the table view.
I'm not sure what to call this functionality or how to achieve this.
Can you guys please give me direction to proceed ahead...
#Sarat,
I assume you wanted to develop this Prototype for iOS or Android App, so using Titanium I've below suggestion for design & functionality
To Achieve Design:
For Android - Use Relative Layout with List view which you can load Rating/Review Icons on top with Fixed Position
For iOS/iPhone - Add Parent VIEW and then Add Table VIEW to load Restaurant and Add Rating/Review Icons in Another Table VIEW with Same Top position of Restaurant List
To Achieve Functionality:
You will get First cell index of Table View in which Restaurant List you're loading, so keep check which Cell of Table is on Top of Table view using Cell Identifier.
Wouldn't it be much easier to just include it as a part of the row? Otherwise the user can only see one rows information at a time, which I would consider bad design.
More importantly, this will not work on iOS unless you add a lot of dummy table rows at the end of the TableView, since the user wont be able to scroll the bottom-most row to the top of the screen!
This tutorial shows you how to have custom table rows. Use it as a starting point to add your comment and like button images. I really see no other alternative, since your fixed position method requires hacking the TableView component or using transforms to move the bottom row to the top.
EDIT:
If you must do it this way, the best way forward would be to add a number of blank table rows to past the end of your real table rows so that the user can scroll all the way down to the last row with content (this way the fixed position can detect its over it).
Next create your view holding the three buttons, making sure its absolutely position in the window (so it stays fixed) and has a zIndex greater than the TableView:
var likeAndCommentHolderView = Ti.UI.createView({
top : 45,
left : 0,
//.... etc
zIndex : 101
});
window.add(likeCommentHolderView);
Now you have to figure out which row the user is over. This can be done using the scrollEnd event of a TableView and getting the contentOffset attribute of the event. The 'scrollEnd' event is triggered when the user has finished scrolling the rows in a tableView, it returns an event that has the contentOffset, which is just a measure of how much you have scrolled from the top of the tableView. Using simple math, calculate the offset divided by the rowHeight and that is the row index the user is looking at.
// Assume table view is at coordinates : top=45, left=0 and you have defined rowHeight
tableView.addEventListener('scrollEnd', function(e) {
// Use this to determine which row your over
var contentOffset = e.contentOffset;
// Figure out the index
var rowIndex = contentOffset / rowHeight;
// Get the row, assume first section
var section = tableView.data[0];
var rowObject = section.rows[rowIndex];
// Now update your UI with data from the row
var name = rowObject.restaurantName;
});
Now you have the actual row object in the table, you can extract
This is only a general outline, this does not take into account some of the differences between platforms, I leave that to you to figure out, but this is a good general approach.
I have a view-based NSTableView that I'm backing with an `NSMutableArray . Periodically I go out grab some data and want to insert new rows into the table at the top.
When I do this without specifying an animation to insertRowsAtIndexes:withAnimation: it seems to work fine for hours on end. However, if I specify an animation, after about 7 or 8 inserts the table view starts to show blank rows where the inserts occurred. Scrolling down and then back up causes the new rows to render properly.
The code that calls insertRowsAtIndexes:withAnimation is in a block, and not running on the main thread, but my inserts happen inside of dispatch_async on the main queue, so I dont' think it related to multithreading.
Here is some code ... self.contents is my NSMutableArray.
dispatch_async(dispatch_get_main_queue(), ^{
[self.contentsTableView beginUpdates];
if(posts.count) {
for(NSDictionary* dictionary in [posts reverseObjectEnumerator]) {
FNPost* post = [[FNPost alloc] initWithDictionary:dictionary width:self.contentsTableView.frame.size.width];
post.delegate = self;
[self.contents insertObject:post atIndex:0];
[self.contentsTableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:0] withAnimation: NSTableViewAnimationSlideLeft];
}
}
[self.contentsTableView endUpdates];
});
One thing I'm confused about is the part of the Apple NSTableView documentation for insertRowsAtIndexes:withAnimation that says:
The numberOfRows in the table view will automatically be decreased by
the count of indexes.
I'm confused by what that statement implies about the relationship between the number of objects in my array (and hence the result of numberOfRowsInTableView:) and the number of rows the table view thinks it has. To my thinking the number of rows in the table view should equal my array count and I want to make sure that my understanding of this is not at the root of the problem but like I said, the table works fine if no animation is specified.
Am I doing something obviously wrong here?
This issue turns out to be caused by having the NSTableView in a layer based view hierarchy. Two superviews up, I had a layer-backed view. After reading some other posts about NSTableView showing other errant behavior when in a layer-backed hierarchy I decided to turn off the layer in IB. Table animations now occur as I would expect at the expense of having to maintain some additional state to control the layer backing state when I want to use CA transitions between my views.
Ok, I am creating an app that serves as a virtual catalog for certain items. The problem is that there are over 600 items that need to be cataloged, and that's is extremely time consuming because I have to first add these items to a table cell viewer, along with the image of the item, then also insert a picture and 3 items of text into a view controller. Is there any way I can create a single view (or similar), and then when the user taps on the table cell that's connected to the single view, it's connected to code that will insert those items into defined spaces in the single view controller?
This app is using ARC and Storyboards. I am using Xcode 4.3.3 with iOS 5.
You can have an array of images or image URLs along with title, description, etc. and then use a grid view of some sort to lay them out (Sam Soffes' grid view or just a UITableView)
And then use code similar to this, where "configure the cell" means:
cell.title = [titles objectAtIndex:[indexPath row]];
cell.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[imageURLs objectAtIndex:[indexPath row]]];
cell.description = [descriptions objectAtIndex:[indexPath row]];
If you can get the urls and text in a CSV file onto your device, then you can build the array with Dave DeLong's CSV parser.
I have a mac app that uses tableView that has some rows.On taping(single tap ) a particular row, I want that row number.Actually , I want to set the value of the label based on the row number selected.Please help!
Your table delegate can implement - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row;
Seems like that'll give you the row you want, then just return "YES" to allow the selection.
Or your delegate could implement - (void)tableViewSelectionDidChange:(NSNotification *)notification; and then get the currently selected cell (though if you allow multiple selection this might not be sufficient).