Reputation: 9241
I am developing app where users can create Posts with attachments. For attachments I have used UITableView
and rotated it in horizontal mode in viewDidLoad
method as following:
// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(-1.5707963);
imageAttachmentTableView.transform = transform;
When the user chooses images from Photo Library, they are loaded in UITableView's imageView.
- (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];
}
// Configure the cell...
CGAffineTransform transform = CGAffineTransformMakeRotation(1.5707963);
cell.imageView.transform = transform;
cell.imageView.frame = CGRectMake(0, 0, 110, 110);
cell.imageVenter image description hereiew.image = [imageAttachments objectAtIndex:indexPath.row];
return cell;
}
cell.imageView
is again rotated in opposite direction so that image should be visible in actual orientation
UITableView is made in editing mode so that when the images are loaded, they can also be removed by single tap.
- (void)viewWillAppear:(BOOL)animated {
[imageAttachmentTableView setEditing: YES animated: YES];
}
I have also changed the default "Delete" text to "X"
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"X";
}
The code is working perfectly in Portrait mode as in following screen, when the user taps '-' button 'X' appears.
http://img5.imageshack.us/img5/1125/screenshot20121221at742.png
Problem is in Landscape mode, the (-) button appears but 'X' button does not appear. http://img833.imageshack.us/img833/6305/screenshot20121221at747.png
I have tried all possible solutions, but could not make any stick, please help
Upvotes: 0
Views: 829
Reputation: 9241
Solved it!
Problem was that in landscape mode, the UITableViewCell size and Delete button frame was changed, so i subclass UITableViewCell
with my custom class.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
OMAttachmentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[OMAttachmentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
CGAffineTransform transform = CGAffineTransformMakeRotation(1.5707963);
cell.imageView.transform = transform;
cell.imageView.frame = CGRectMake(0, 0, 110, 110);
cell.imageView.image = [imageAttachments objectAtIndex:indexPath.row];
return cell;
}
In my OMAttachmentCell
class, i implemented the following method.
-(void) willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
CGRect f = deleteButtonView.frame;
f.origin.x = 0;
f.origin.y = 0;
f.size.width = 30;
f.size.height = 34;
CGRect sf = self.frame;
sf.size.width = 110;
sf.size.height = 110;
deleteButtonView.frame = f;
self.frame = sf;
}
}
}
}
Here i just updated the Delete Button frame and TableCell size.
Upvotes: 1