UITableCell turning blank after clicked - iphone

Im using a regular uitableview with regular uitablecells on it with some text and an image on them. When a cell is clicked I perform tableView: didSelectRowAtIndexPath:, in the end I call [tableView deselectRowAtIndexPath:indexPath animated:YES]; and everything works fine. But in the meantime before the next view loads its contents from the web, the clicked cell turns completely blank. Any clue on that?

If your problem is that you don’t want to show the touched UITableCellView as selected you can try cell.selectionStyle = UITableViewCellSelectionStyleNone;
Maybe if the problem is the load of the new UIView you can use NSThread and detach the process from the main thread.

Related

UITableView deselect selected cells after editing

I have multiple cells selected in a UITableView, but they automatically get deselected after editing. I searched a bit and I saw people saying that they called 'reloadData' which has caused the selections to be removed, but I do not call reloadData anywhere except for in 'viewDidAppear'. They get deselected even if the editing has been cancelled without changing anything (when clicking 'edit' button in the toolbar then clicking 'done' button without any editing). I'm not sure where this is happening. Or, if I could detect when the editing has been finished (when 'done' button has been clicked), I could simply reselect all the cells that had been selected, but I'm not sure how I could detect it..
How could I prevent the cells from getting deselected? Or reselect the cells after the edit?
Thanks in advance.
I presume you are trying to achieve selection and deselection on Button press, If you are trying to change the state of selection in a UITableViewCell try using the method in the button action.
-(IBAction) someAction {
if(buttonToggled){
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}else{
//Do something
}
}
for changing the backgroundColor.
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.selectedBackgroundView.backgroundColor=[UIColor blackColor];
for more information on the above please check the link.
UITableView Cell selected Color?
I would suggest the best bet is just to reselect them yourself after every press on your "done" button.
It is quite normal that cells get deselected or buttons get unpressed, since this is their normal state - exept if you write your own code to change this - like in your case.
This is how to select a row:
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
If you have multiple rows that can be selected make sure you have the settings accordingly, otherwise it might always deselect all but the most recent rows.
Nevermind. I found out that - (void)setEditing:(BOOL)editing animated:(BOOL)animated gets called whenever the 'edit' or the 'done' button has been clicked.

Why tableview cell background view working well after navigation back?

At this moment i am working on iPhone 5.0 simulator.In my tableview i have taken a uiview for each cell background color and this view has a background image.
Now, My problem is when my table containing controller load then in the- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
i have wrote this for table cell background.
cellView = [[[UIView alloc] initWithFrame:CGRectMake(0,8,250, 51)] autorelease];
cellView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"order_text_area.png"]];
cellView.tag =10;
[cellView.layer setOpaque:NO];
cellView.opaque = NO;
[cell.contentView addSubview:cellView];
For keeping cell background transparent i have used this code and it works,But
[cellView.layer setOpaque:NO];
cellView.opaque = NO;
when i select a cell then it goes it's corresponding controller.Now my problem is when i return back to my tableview controller then cell background do not keep in transparent view means cell view do not work on those code.So anybody help me. I am in serious problem.
NOTE THAT *I wanted to give a screen shot but unexpectedly in simulator i do not face this problem.*
Thanks In Advance.
If you are making a change to the cell background directly in your code, what is probably happening on the device is that when you move to the next screen, the tableView on the previous screen is being unloaded to save memory, and when you go back to it, it is re-loaded and the cells are created again by calling your tableView:cellForRowAtIndexPath: for each cell.
This would also explain why it doesn't happen in the simulator, which is less memeory-constrained and so probably isn't unloading the view. Try simulating a memory warning in the simulator on the second page and then going back to the first view and see if your cell is de-highlighted like it is on the device.
To make the effect persist after the view is reloaded, you will need to remember the cell index that was highlighted before pushing the new view, and then re-highlight the correct cell in your tableView:cellForRowAtIndexPath: method when it is re-created.
do you have
[self.tableView reloadData]
in will appear?
if you already have, try to put a tag at the table view, in the will appear, remove the tag from super view and recreate the table.
hope i understand the question.

iPhone - changing contents of a UITableViewCell inside a navigationController

I have a UITableView with some cells in it that have people's names. When the user clicks on a cell, the Navigation Controller pushes a new view onto the stack that shows detailed info for that person. When the user is done and clicks the button to return to the previous view, the tableview is again shown. The problem is that I want to edit the cell text (or just mark the cell in some way) to show that the user has clicked on that cell. In my cellForRowAtIndexPath: method I have set up code that should change the text of the cell after a user clicks on that cell. I set up break points and it IS entering cellForRowAtIndexPath: when the detail view is popped and the tableview is again shown. It's entering the segment of code in cellForRowAtIndexPath: that should change the text, but when it comes up on screen, the text has not been changed. Does anyone have any ideas as to what is going on? Thanks.
EDIT: I figured it out. I just needed to call [tableView reloadData]; instead of calling the cellForRowAtIndexPath method. Not sure why that works differently, but it fixed it.
I guess I'll help you out. You don't need to credit me with the answer though.
cellForRowAtIndexPath:
that method is called within the framework when a cell is being refreshed from the queue or when it needs to be created. You should not call this method.
[tableView reloadData];
that method is basically a refresh on all of the visible cells show in the UITableView. This is the method you should call if you change information in your data source or you need to (force) update the appearance of your cells.
It's Good You Have Reload Table And Changed The Text But If YouJustIndicate NAd Don't Want To Change The Text The nYou Can Use elow Given Text ....
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
It Will Check Mark Particuler Cell Which You Click/Visited......
Hope You Like This Solution.....

Reload tableview iphone developer

I have a feed reader that read automatically the homepage of my website! But when I change the feed URL and reload data the cell isn't reloaaded! Infact I must scroll the cell view (infact with this action is called the didselectrowatindex method) to reload data in the cell with the new ones.
I tried [tableview reload]; without any results....
Is there a method to reload all content in the cell without scrolling it?
Thanks
Well, it should be [tableview reloadData]
If it's not working, then maybe you have a problem with your IBOutlet?

iPhone didSelectRowAtIndexPath not firing

So I am trying to default to having the first row in a tableView selected when my view first loads. I am doing this my viewWillAppear method:
NSIndexPath *tempPath= [NSIndexPath indexPathForRow:0 inSection:0];
[theTable.delegate tableView:theTable didSelectRowAtIndexPath:tempPath];
Which fires the method, but the cell doesn't stay selected. This fires the proper method and executes the code in there, and I am never deselecting it. After the user presses another cell, it stays selected properly. Just not the first time. Does anyone know what may be causing this weirdness? I have even tried to do this:
[[theTable.delegate tableView:theTable cellForRowAtIndexPath:tempPath] setSelected:YES];
Thoughts?
First of all, you shouldn't be calling the delegate methods directly like that.
If you do need to select a cell programmatically (like the Mail app does), use the selectRowAtIndexPath method:
[theTable selectRowAtIndexPath:tempPath animated:YES scrollPosition:UITableViewScrollPositionBottom];
According to the HIG, you aren't supposed to leave table view cells in a selected state. You are encouraged (strongly) to deselect the row as soon as you perform whatever action the tap requires.
For persistent selections, you are supposed to use the accessory, and you can set a cell's accessory to a checkmark to indicate "Selected"