how to remove invisible tableview cell's downloaded image . in ios - iphone

I want to remove downloaded image in invisible tableview cell when I scrolled tableview.
So I set a tag
- (void)appImageDidLoad:(NSIndexPath *)indexPath
{
int row=(int)indexPath
UITableViewCell *cell;
cell=[self.gamesTableView cellForRowAtIndexPath:indexPath];
OneItemCell *cell1=(OneItemCell*) cell; //custom cell
cell1.imageview.tag= row+100;
}
I set remove downloaded image when selected row is last row cell(=add cell).
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(row==nArrayCount)
{
if(row>19)
{
for(int i=1;i<row-8;i++)
{
[[self.gamesTableView viewWithTag:i+100] removeFromSuperview];
}
}
}
but it is not working . because [[self.gamesTableView viewWithTag:i+100] is NULL.
another way I set a key to cell's imageView by NSMutableDictionary(=imageRemoveInProgress)
- (void)appImageDidLoad:(NSIndexPath *)indexPath
{ .
.
[imageRemoveInProgress setObject:cell1.imageView forKey:[NSNumber numberWithInt:row+100]];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ .
.
[[imageRemoveInProgress objectForKey:[NSNumber numberWithInt:row+100]] removeFromSuperview];
}
it is not working too . because[[imageRemoveInProgress objectForKey:[NSNumber numberWithInt:row+100]] is NULL too.
[[imageRemoveInProgress objectForKey:[NSNumber numberWithInt:row+100]] has value in appImageDidLoad.
but In - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
it has NULL.
why do taged and seted key value cell's imageView become NULL?
how to remove tableViewcell's imageview?

I don't know the exact way, But I can provide a hint to do it
you can use something like this
NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
visiblePaths is an array of indexPaths of cells that are currently visible, you can check whether the cell for which you want to remove the image lies in this array or not.

Related

Need to enable UITextField in row of UITableView when cell is selected in iOS

I have created a custom cell that places a UITextField in each row of a UITableView. What I would like to do is enable the UITextField for a particular row (i.e. activate the cursor in that textfield), when the user presses on anywhere inside the cell.
I have the following method where I try to do this:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[_cell.textField setUserInteractionEnabled:TRUE];
}
However, this is not working. Can anyone see what I'm doing wrong?
You're on the right track placing this inside didSelectRowAtIndexPath:. However, setting user interaction enabled on the textfield just means that the user would be allowed to interact with the object if they tried. You're looking for becomeFirstResponder.
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.textField becomeFirstResponder];
}
Try this code:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[_cell.textField becomeFirstResponder];
}
What is this _cell iVar? Are you setting it somewhere?
I think what you are trying to accomplish is this:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell.textField becomeFirstResponder];
}
Notice that in this way you are getting the cell for the tapped indexPath.
And also, just for information, it's a pattern in objective-C to use booleans as YES or NO, instead of true or false.

Grouped Style UITableView doesn't clip subviews

I have a design issue with grouped uitableview, I add uiviews to the leftmost side of each cell extending little over the cell bounds and I want them to be clipped. But neither setting clip subviews in IB nor setting clipsToBounds property in code didn't help.
So far I have set clipsToBounds (for both uitableview itself and individual uitabviewcells) in a number of places but none helped:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
...
[cell setClipsToBounds:TRUE];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:defaultIdentifier];
if (cell == nil)
{
cell = [self reuseTableViewCellWithIdentifier:defaultIdentifier withIndexPath:indexPath];
}
...
[cell setClipsToBounds:TRUE];
...
return cell;
}
- (void)viewDidLoad
{
...
[mainTableView setClipsToBounds:TRUE];
}
Is it possible without changing tableview style to plain?
Update: My previous answer was wrong. Here is an answer that actually shows how to do what you're asking.
https://stackoverflow.com/a/401271/350467
.......
Previous Answer
If you're adding views to the cell's contentView (which you should be, unless you have a good reason), you'll want to set cell.contentView.clipsToBounds = YES;

Open UITableview or view when the main UITableView cell selected

I have a UITableView which has master records in it's cell. When the user selects a cell, some detail record is displayed on the same table and this record would be set below that particular cell.
One more thing is the cells that are below the selected cell of the master table will be displayed below the detail view.
In short I want to design a popup that will display the details of selected cell below that particular cell and rest of the cells(cells below the selected cell) of master will be moved down, so that the detail popup can be accomodated between the selected cell and the cells below it.
//Take int selectedCellIndex in your .h file, initialize selectedIndex with -1
//Take BOOL isSelected in your .h file
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedCellIndex = indexPath.row;
isSelected = YES;
[yourTable reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==selectedCellIndex)
{
return 100;
}
return 50; //Your default cell size
}
- (UITableViewCell *)tableView:(UITableView *)tV cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//after creating your cell
if(isSelected && selectedIndex>-1)
{
//Show your custom View , something like [cell.contentView addSubView:customView];
isSelected = NO; //Reset
selectedIndex = -1; //Reset
}
}
You can simply use this
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method . In here, You can allocate a new UIView every time the user clicks on the cell and display your information in it.
If you have any queries please feel free to reply . :)
Check these projects out, maybe they will of some help ...
Combo Box

UILabel is not showing values from the UITableview

Sorry guys its me again.
In my project i used UITableview for showing weather.so, I need to show the first row text to UILabel without any button action or watever. I just want cell text to UILabel without any action.
ex:
In the tableview first cell showing text as "Lovely IOS"
I want to show the same text to UILABEL without any action. I took UILabel in the xib.
Thanks in advance
Any sample code please.
you only set action for particular cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1){
//set action for cell
}
}
In the method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath equate
cell.textLabel.text = [array objectAtIndex:indexPath.row];
LabelName.text= cell.textLabel.text;
You have two options for this either you add add UILable or set the text to he cell.textLabel.text in the following method.
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
You have the data for your cell so what's a big to UIlabel .You just need to set the same text there.
Updated:-
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = cell.textLabel.text;
you will get the text.

How to make UITableViewCell highlighted state persist

I have a UITableviewCell. When a user clicks the cell, Im saving the indexpath and then calling the cellforrowAtIndexpath method to get the cell and then call the SetHighlighted:TRUE on that cell.
This works fine but the problem is when I scroll up and down the tableview, the selected cell when reappears, is not highlighted. How do I make the highlighted blue color persist so the user can visually see their selection even after scrolling the table up or down?
Thanks
save the indexpath of the selected cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndexPath = indexPath;
}
and compare in tableVIew:cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// configure cell
if ([indexPath isEqual:self.selectedIndexPath]) {
[cell setHighlighted:YES];
}
else {
[cell setHighlighted:NO];
}
return cell;
}
However, keep in mind that apple discourages the use of the cell highlight state to indicate selected cell. You should probably use cell.accessoryType = UITableViewCellAccessoryCheckmark;