How many UITableView can place in a View? - iphone

I'm beginner in Iphone!
Can I place many UITableView (greater 1) in a View? And how to control them?

You can place as many UITableViews into a parent view, but it's probably not a good idea. Each delegate and datasource method for a tableView takes that tableView as its first argument, so it's easy to tell them apart.

Well its not a good idea to have multiple tableviews in a view but if you want it you can have them and control the by there names like
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(tableView == declaredTableView1){
return 10;
}
else if(tableView == declaredTableView2){
return 11;
}
else {
return 12;
}
}
Hope this helps.

Related

how to remove button in Uitableview when table is int edit mode

I creating the one UITable view with the 2 sections in with when i load the data into the uitablew it's working fine,
But my problem is how to resolve one sorting button is disable in section 0 and row 0
which more discribe into the following image.
please help to solve my problem
in advance thanking to your valuable time spend on my problem.
It's quite easy.
Listen on the UITableViewDataSource call tableView:canMoveRowAtIndexPath:
Like this:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0) {
return NO;
}
return YES;
}
If you don't not where to place the method, place it next to tableView:cellForRowAtIndexPath:
Set showsReorderControl to NO property of cell
cell.showsReorderControl = NO;
In addition, if the data source implements tableView:canMoveRowAtIndexPath: to return NO, the reordering control does not appear in that designated row. You need to check indexPath and return NO for it.

Prevent cell from being created

In a tableview, I need to prevent a cell from being created by a given condition.
For example, I have a tableview that shows a couple of results but I want the app to filter them. Is a way to do this?
Best Regards.
Preventing a cell from being created doesn't sound good. The simplest way to do that is to implement correctly the ...numberOfRowsInSection: method given the condition :
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(condition) {
return theNumberOfRowsGivenTheCondition;
}
else {
return someOtherRowsCount;
}
}

Tableview with 2 section

Hello
I am developing an app which is using a tableview with two sections(instead of radio buttons).
So I want these section to act like radio buttons. To accomplish this, I have to implement an "if" in the
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
I want to use something like: if (section == "A").
How to do that?
Also is this the right way to make the sections of a table acting like a different tables?
Hmm... that sounds like an odd set up, but irrespective, you simply use the provided indexPath to obtain the section/row.
i.e.: indexPath.section will point to the selected section and indexPath.row will point to the row.
For more information, the Table View Programming Guide for iOS is a good start as it covers all of the above in quite a bit of detail.
UPDATE
In terms of highlighting multiple cells, I'd have thought that you'd want to create your own concept of highlighting, which you'd toggle on and off when the user selects the cell.
That said, you could also mark selected cells via the UITableViewCellAccessoryCheckmark as per the existing Is it possible to configure a UITableView to allow multiple-selection? question/answer.
I don't know what you mean by "section to act like radio buttons" but to distinguish between sections in tableView:didSelectRowAtIndexPath: use indexPath.section:
if (indexPath.section == 0) {
// first section
} else if (indexPath.section == 1) {
// second section
}
you must need to use indexPath.section: to distinguish between your table sections
So your code should be like below .
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
{
if (indexPath.section == 0)
{
//first section
}
else if (indexPath.section == 1)
{
//second section
}
}

UITableView fixed header

How to disable scrolling for UITableView header, to be always visible? (To have column titles.)
I am not sure if I am getting what you mean, are you using a UITableViewController?
If you want to have a header that is not scrollable maybe you can try to put a UIView at the top of your tableview and add sublayers to it as needed.
If a tableview with multiple fixed section headers is what you want, I would suggest using different tableviews and adding UIViews on top of each one for the header.
For handling delegate and datasource use NSObject's - (BOOL)isEqual:(id)anObject .
For example:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([tableView isEqual:markosFirstTableView])
{
return 1;
}
else
{
return 5;
}
}
Does this help?

How to display Two tables on a UI view

I would like to use and display two tables on a UI view. Please let me know how to do this. Any code same will also be appreciated.
Thanks,
Sandeep
Add 2 UITableViews to your view in IB and connect them to 2 different outlets in file owner (or simply assign different tag properties).
Set delegate and data source for them (may be same view controller for both).
In delegate/data source methods you do the following:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == myFirstTable)
// return value for 1st table
if (tableView == mySecondTable)
// return value for 2nd table
return 0;
}
or if you use tag approach:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
switch(tableView.tag){
case firstTag:
// return value for 1st table
case secondTag:
// return value for 2nd table
}
return 0;
}