I have an old iOS app written in objective c. It has several UILabels that has given fixed x,y,width and height. Now what I want to do is when click on the acessoryView expand the cell and expand the UILabels inside it. Also I want to change the positions of those UILabels. So far I have done cell expanding part in this way.
- (void)expandCell :(UIButton *)sender {
NSLog(#"NSINdex Path-------%li",(long)sender.tag);
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
MetadataTableViewCell *cell = [_metadataListTVCTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag inSection:0]];
if (newIndexPath == cellExpandedRow) {
cell.isExpanded = true;
}
else {
cell.isExpanded = false;
}
cellExpandedRow = newIndexPath;
[_metadataListTVCTableView beginUpdates];
[_metadataListTVCTableView reloadRowsAtIndexPaths:#[[NSIndexPath indexPathForItem: sender.tag inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[_metadataListTVCTableView endUpdates];
[_metadataListTVCTableView reloadData];
}
But I have no idea where I can do inner label frame updatings. Please help me. Thanks
Related
I don't know why this doesn't work. indexOfIcon is correct, section is correct (checked with NSLog) If I select one everything is correct. But this line doesn't do a thing...why? If selected it should have a blue border. This works great while doing it "manually" but not with code..
- (void)viewWillAppear:(BOOL)animated
{
NSUInteger indexOfIcon;
if(self.mainCategory.icon){
indexOfIcon = [self.icons indexOfObject: self.mainCategory.icon];
} else {
indexOfIcon = 0;
}
[self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom];
}
add
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.selected = YES;
and the cell will be selected.
The command [self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom]; tells the collectionView, that the cell is in selected state, but don't set the state of the cell.
After years selection seems to work fine (even in viewDidLoad:)
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[_collection selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionLeft];
successfully triggers cell's -setSelected:
i have a menu that contain 6 cells 1st one contain UIViewController the second contain UITableView
when i click the first cell a new page appear,and it contain a button
when i click this button i want access to the second cell from the Menu, that contain a tableView
// use this code for to Refresh or delete or insert TableviewCell
// reloading cell
NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil] withRowAnimation:UITableViewRowAnimationTop];
// inserting cell
NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil] withRowAnimation:UITableViewRowAnimationTop];
// deleting cell
NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil] withRowAnimation:UITableViewRowAnimationBottom];
As much i understand your question you want to move from a tableview to other view on click..So,you have to use code similar to this..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Detail *img1=[[Detail alloc]initWithNibName:#"Detail" bundle:Nil];
img1.labelString = [titleArray objectAtIndex:indexPath.row];
[self presentViewController:img1 animated:YES completion:nil];
}
Write following coed in your UIButton Tapped Method.
-(void) ButtonTapped:(UIButton *) sender
{
NSIndexPath *indexpathNew = [self.tblView indexPathForCell:(UITableViewCell *)[sender superview]];
NSLog(#"%#",indexpathNew.row);
}
indexpathNew is return indextPath of selected button of cell.
Try my code i might be helpful to you.
I can get a reference to the cell quite easily
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
But I need to get a reference to the little handle on the righthand side of the cell when in edit/reorder mode. How can I do this?
you can find it with this code, but the reorder-control is private-api
for (UIView *view in cell.subviews) {
if ([NSStringFromClass([view class]) isEqualToString:#"UITableViewCellReorderControl"]) {
// 'view' is the reorder control
}
}
You need to use the editingAccessoryView property on your cell :
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
UIView *editingAccessory = cell.editingAccessoryView;
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//case 1
//The user is selecting the cell which is currently expanded
//we want to minimize it back
if(selectedIndex == indexPath.row)
{
selectedIndex = -1;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
//case 2
//First we check if a cell is already expanded.
//If it is we want to minimize make sure it is reloaded to minimize it back
if(selectedIndex >= 0)
{
NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];
}
//case 3
//Finally set the selected index to the new selection and reload it to expand
selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Notice how case 1 and case 2 are related collpasing already expanded row where as case 3 is about expanding the unexpanded row.
Both the expand and collapse use the same function of reloadRowsAtIndexPaths function.
The question for me is that a toggle button, when it's expanded, run that function again will collapse and when it's collapsed, it will expand??
What will happen is that when you call reloadRowsAtIndexPaths: the table view will reload those rows by calling your implementation of tableView:cellForRowAtIndexPath: in your UITableViewDataSource. It is up to you to return a cell there which uses the selectedIndex variable to decide if it should appear expanded or collapsed (whatever that means for your specific application). It will also call tableView:heightForRowAtIndexPath: on your UITableViewDelegate (yes, it is silly that this is in the delegate) so if your cell height changes this method too should return a value depending on selectedIndex.
Also, I would suggest you only call reloadRowsAtIndexPaths: once, like this:
NSMutableArray* rows = [NSMutableArray arrayWithCapacity:2];
// Case 2
if(selectedIndex >= 0)
{
NSIndexPath* previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
[rows addObject:previousPath];
}
// Case 3
selectedIndex = indexPath.row;
[rows addObject:indexPath];
[tableView reloadRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationFade];
I want to add cells into UItableView like in mail.app on ipad. In my cells I have UITextFields, and I have change this method to set focus
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath{
NSLog(#"%d",newIndexPath.row);
UITextField* field = (UITextField *) [tblView viewWithTag: newIndexPath.row];
int l_cellNum = field.tag;
if(l_cellNum == 1 && isAddedNewRow == FALSE){
isAddedNewRow = TRUE;
[cellsArray insertObject:#"CC" atIndex:1];
[cellsArray insertObject:#"BCC" atIndex:2];
CGRect tvbounds = [tblView bounds];
[tblView setBounds:CGRectMake(tvbounds.origin.x,
tvbounds.origin.y,
tvbounds.size.width,
tvbounds.size.height)];
NSIndexPath *path1 = [NSIndexPath indexPathForRow:1 inSection:0];
NSIndexPath *path2 = [NSIndexPath indexPathForRow:2 inSection:0];
NSArray *indexArray = [NSArray arrayWithObjects:path1,path2,nil];
[tblView insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationTop];
[tblView reloadRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
[field becomeFirstResponder];
}
But when I click to one of the cell i add 2 cells (like mail.app) but my tags for textFields do not updates, and I cant to set focus on it =(. If I call reloaddata method it calls -cellForRowAtIndexPath with this new cells at the beggining and after for all cells, and it will not work too.
It sounds like what you're looking for is a built-in style of cells called UITableViewStyleSubtitle, where you can customize the subtitle just like the iPad Mail.app. Take a look at this page in the iOS documentation. Then, you can set the subtitle of the UITableViewCell to the text that you need.
Additionally, the iOS doc has more information about customizing table view cells.