Hierarchical UITableview - iphone

In my first view I have a UITableView with 5 records. In UITableView cells are holding two different components. One UILabel is text and another UILabel shows value for that cell.
On selection of this UITableViewCell user is navigated to another view where I have given a picker controller for changing the value of 2nd label in the table view for the selected row. I reload the UITableView data on -viewWillAppear but this overlaps the text on lables as many times I visit it.
Can anyone give me relevant example of hierarchical tableview where UItableViewCell's right section is dependant on selection of picker from next view.

I think you are adding the labels on cell.contentView everytime you reload the table, but are not removing the previous ones. Thats why the overlapping is happening.
try to remove the lables
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
for (UIView * view in cell.contentView.subviews) {
[view removeFromSuperview];
view = nil;
}
// add your labels
}

Related

how to cascade uitableview's width to its custom table view cell?

I have a certain sized UIView used as a container of a UITableView. I use a subclass of UITableViewCell in my table view.
The problem is that my custom table view cell can not get the proper width from the UITableVIew.
This is how I create the table view
categoryListView = [[UITableView alloc] initWithFrame:categoryListContainer.bounds style:(UITableViewStylePlain)];
This is how I create the custom table view cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == categoryListView) {
static NSString *CellIdentifier = #"MenuCategoryListIdentifier";
MenuCategoryListCellView *cell = (MenuCategoryListCellView*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// create dynamically
cell = [[MenuCategoryListCellView alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:CellIdentifier];
}
....
I wish to be able to get the correct cell bounds to in my MenuCategoryListCellView's initWithStyle method to draw my UI controls. But I don't know how to pass the value down.
Help will be appreciated!
Leo
The system will send the layoutSubviews message to your cell when the cell is resized. Override that method to lay out the UI controls according to the cell's current size.

Add Blank Cell to each Group in UITableView

I have a tableview that has groups. I would like to add a dummy cell at the top of each group, but not add it to the data. I dont want it saved. So if the top cell is clicked, its data passed will be blank and I can handle the passed view differently. I currently am configuring the cells manually.
So if group one had two entries, the display of those two entries would be prepended with a fake entry at what would be index 0
Below is a preview of what I am trying to do.
PS: Can one cell have a different disclosure icon? Does that break Interface Guidelines?
It would be something like this, you are not really adding anything to your model, you are just modifying your view:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if ([indexPath row] == 0) {
//And any other default behavior
[[cell textLabel] setText:#""];
}
else{
//Your code for each cell
}
return cell;
}
The HIG doesn't mention anything about having different disclosure icons:
iOS includes some table-view elements that can extend the functionality of table views. Unless noted otherwise, these elements are suitable for use with table views only.

How to fix Row in table in Uitableview in iphone

I am small basic module. I have 3 screen in this module. First screen is welcome message showing. Second screen is Table view which is contacting 3 Row with the title. Whenever user will select any row Full Text will be open for selected row. Last screen is containing one BACK button which will back to second screen (on tableview screen).
I have done this all till last screen. But when I am clicking on back button I am going on table view screen but I am seeing more than 3 row are showing on Simulator.
I wrote this code on button click function for backing to second screen (table view screen)
...
MyViewController *History_Back = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
[window addSubview:History_Back.view];
[self.view addSubview:History_Back.view];
....
And in TableView implementation class i am defining it in viewload function which is like below..
-(void)viewDidLoad {
NSLog(#"::::::::::::::");
tableList = [[NSArray alloc]initWithObjects:#"A",#"B",#"C",nil];
[super viewDidLoad];
}
And i want to show only 3 row. Where I should to modify code ?
My tableview coe is here.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[tableList objectAtIndex:[indexPath row]];
NSLog(#"##############");
return cell;
}
By default, a UITableView will display as much rows as the tableView height allows (even if the content of the cell is empty). In order not to display more than 3 rows, you have two solutions :
either you resize your table view height to the appropriate height
or you can add tableView.separatorStyle = UITableViewCellSeparatorStyleNone; in the definition of your tableview. This means that you will have to add your own custom separator in the UITableViewCell design...

Values are getting cleared from UITableViewCell while scrolling

I have placed three buttons over UITableViewCell and its background is set to an unselect radio button image.
While clicking the button I'm again setting the background image as select button.
In a row one select button should persist but while scrolling UITableView all the selected button images are getting cleared
Can somebody please give me any idea how to do this in this way or in other way ?
You probably are not reusing the cells correctly. When you scroll, a previous cell is reused by the UITableView, but you don't change its contents correctly. Here is a sample code for ur reference
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
}
cell.textLabel.text = [urDataArray objectAtIndex:indexPath.row];
return cell;
}
save the state of you button in table datasource.
set that value to your button. table is reloading each displayed row while scrolling.

UITextView in iphone

i am creating textview(editable) through coding in uitableview in cellforrowatindexpath delegate. textview is showing in every row correctly. the problem is that when i am enter text in textview and scroll the tableview, then text disappear from textview. if anyone has any idea?
When you go to edit the text in the textview, the text scrolls up so that the top of the textview is where the new text will appear when typed. Try swiping down on the textview to reveal the previous info.
Make sure you are adding a different textview to each of the different reusable cells. If you have, say, 6 cells visible at any time, then you need 6 different textviews.
It sounds like when you scroll, your textview gets used for another cell.
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
MyTableCell *cell = (MyListTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
cell.textView = [[[UITextView alloc] initWithFrame:/** put appropriate rect here **/] autorelease];
// create other cell structures you need
}
// Set up the cell...
}