Reputation: 1563
Basically i want to hide always hide the uiview(with buttons), until a cell is touched then it brings up the uiview from the bottom of the cell with animation(if possible)
something like this:
I saw this in an app and fell in love with it and thought it would be great user experience.
Please how do i archive this, cheers
code so far:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *mycell=[tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];
if (mycell==nil) {
mycell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellIdentifier"];
}
UIView *myview = [[UIView alloc] initWithFrame:CGRectMake(0, 25, 320, 50)];
[myview setBackgroundColor:[UIColor greenColor]];
[mycell.contentView addSubview:myview];
mycell.imageView.image = [UIImage imageNamed:@"placeholder.png"];
mycell.textLabel.text = @"Song Title";
UIFont *myFont = [ UIFont fontWithName: @"AppleSDGothicNeo-Bold" size: 12.0 ];
[mycell.textLabel setTextColor: [UIColor colorWithRed:0.839 green:0.271 blue:0.255 alpha:1]];
mycell.textLabel.font = myFont;
return mycell;
}
P.s myView is the view i want to add, which will contain the buttons . Cheers !!!
Upvotes: 0
Views: 1169
Reputation: 6454
Try like this
First take a global variable
NSInteger selectedIndex;
In viewDidLoad insert value in this -1;
selectedIndex = -1;
after then use in didSelectRowAtIndexPath function insert value in this variable.. Like this and reload with animation.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
selectedIndex = indexPath.row;
//[tableViewObj reloadData];
[tableViewObj reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
and in heightForRowAtIndexPath function manage height for selectedIndex using If/else like this..
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == selectedIndex) {
return 200;
}else{
return 80;
}
return 0;
}
as I seen Have describe fully here .. try this It's working fine because It tested by me right now..
Upvotes: 0
Reputation: 2882
This option would require your UITableViewDelegate
and UITableViewDataSource
to be the same object, which is usually the case.
UITableViewDelegate
's tableView:didSelectRowAtIndexPath:
, you could manage an array of selected indexPath values, and then call [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]]
for the row that was just selected/deselected.tableView:cellForRowAtIndexPath
, you can check if the current indexPath is in the list of selected indexPath managed by the UITableViewDelegate
method, and take the appropriate action to show/hide the additional contentUpvotes: 1