Grouped UITableView Interface Builder Examples/Tutorial - iphone

I'm having an immense amount of trouble figuring out how to populate a Grouped UITableView with custom UITableViewCells. Could anyone point me towards a tutorial on how one might do this? Or does anyone have an example of what a cellForRowAtIndexPath method would look like when creating a Grouped UITableView with custom UITableViewCells?
Thanks.

Here are some guidelines:
Each of your group in grouped UITableView is a section. Then the method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
// Here is first group
if (indexPath.row == 0) {
// Here is first row in a first group
}
}
}
I hope that this makes sense for you

I think you can browse this TableViewSuite sample codes.

Related

How to disable the row selection after specific no of counts in UItableview

I wanted to disable the UITableView cell selection after selecting 10 rows in multiselect UITableView,
After deselecting some rows again user will able to select the UITableView cell.
Can anybody please suggest me, how can i do this?
Thanks for help in advance.
Implement willSelectRowAtIndexPath:indexPath:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.indexPathsForSelectedRows.count < YourMaxRowSelectedCount) {
return indexPath;
} else {
return nil;
}
}
The method indexPathsForSelectedRows returns an NSArray object of index paths of all the selected rows of the table view. You can check count of that to compare to your required number of selected rows and act accordingly.

when I click a UIButton I'm trying to find out which cells are currently selected inside a UITableView

I have 2 UITableViews. When I click the UIButton outside of either UITableView I'm trying to determine which cells are selected in each tableview.
Anyone have a good way of doing this? Would I loop over the cells to determine which cell is currently selected? Or is there already a method that can tell me?
Thanks a bunch!
You can use this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
Take a look at UITableViewDelegate Protocol Reference
UITableViewDelege Reference
EDIT: When the user select a row in one of your tables you can get it using this method and a couple of variables for the table and the cell and then you can pass what you got as soon as the user tap on your button.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
thisIsMyTable = tableView;
thisIsTheSelectedRow = indexPath.row;
}
- (void)buttonTapped {
// Do what you need
}

iphone multiple uitableview in one view

Is there any sample project which shows multiple UITableView functionality?
I am greatly appreciative of any guidance or help.
Check this Sample project, but you need to have an account to download it:
Multiple table views on a single screen
The idea is very simple all you need to do is to distinguish between the UITableView that will trigger the delegates, for example:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == tableView1)
{
[FirstDataSource count];
}
else if (tableView == tableView2)
{
[SecondeDataSource count];
}
}
Please check out my blog post on this topic: http://iappexperience.com/post/23157217438/how-to-add-multiple-uitableviews-in-the-same-view.
Basically you can create a (second) UITableView and put it in the header (or wherever fits your scenario) of another UITableView. Then create a UITableViewController and hook it up with the UITableView in the header.

Adding Data/Rows to UITableView (Multiple Tables on one view)

I've searched around and I can't seem to figure out how to do this. It doesn't help that I don't really know what I am totally doing yet, but I hope this will help.
I am creating an iPad application. In short it is a complex stopwatch that will take splits (for running) on one view.
I have a master clock, and 5 buttons for separate splits. All that works. But, I want to record these splits and I thought it would be great to do it in a table that can be scrolled through.
I have 5 UITableViews on the one view. I found some stuff online for a "datasource protocol" and got everything working great for just one table. Things went to crap when I tried to make it work separately for each table. Also, it seemed like a ton of code for a simple task.
I have 5 mutable arrays already present. I really don't know how to go about this and any help would be great!
Also, if possible, i need to clear the tables with the press of a button...seems simple, but I truly don't know.
Thanks!
You need to set UITableViewDelegate and UITableViewDataSource for all your tables to a class that will implement the following methods:
For UITableViewDataSource:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
and
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
As these methods are passed the calling tableview, it should be easy for you to return the correct data for the tableview in question (which you are already storing in an NSMutableArray). You still need to cater for displaying different content for your arrays, but I trust you will manage to do so. NSIndexPath basically tells you which part of your array should be displayed. Assuming, for now, that you are working in an ungrouped table, you would simple create a new cell and fill it with the contents of your array, which is determined by the indexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"MyNiceIdentifier";
cell = [aTableView dequeueReusableCellWithIdentifier:NavigationCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.tag = 500;
}
cell.textLabel = [myArray objectAtIndex:indexPath.row];
}
In the other data source method, you simple return the count for that array:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(tableView == myFirstTableView) {
return [myFirstArray count];
}
}
The method of UITableViewDelegate you will likely use most often is this:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
which you use to return the desired height for a cell at a given indexPath.
Setting dataSource and delegate is as simply as doing:
myTableView.delegate = ...
myTableView.dataSource = ...
See this documentation:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate
Please also refer to this documentation:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

How do I populate a predefined UITableView to a view using the interface builder

I've created a custom UITableViewCell with a label and a text field.
I want to create two cells in a group to represent a nice username/password input mechanism.
I've run into some troubles figuring it out (things like the delegate/dataSource).
Is there a more direct approach to just add those two cells and get the data inserted into the text fields from code?
P.s. I want the TableView to be only at a part of my screen, the other part will be an "Enter" button...
Plus, if it can do it via the interface builder that would be great.
Although I agree with jer, some pointers about how to still use IB to make table view cells.
Add the cells to your NIB (at root level) and make them look good. Add two IBOutlet UITableViewCell *cell0, *cell1; to your header. Hook up the cells in the NIB to these outlets.
In the class which is your dataSource, do something like:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath row])
{
case 0: return cell0;
case 1: return cell1;
}
NSLog("Something bad happened");
return nil;
}
Interface builder doesn't know about your table view data. If you are confused about setting up a data source, then read the documentation, try the sample code, explore until things make sense. Ask when you get frustrated.