Reputation: 199
Here is my code,
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
if ([cell.textLabel.text isEqualToString:@"Small" ]) {
cell.imageView.image=nil;
cell.accessoryView = nil;
cell.accessoryType=UITableViewCellAccessoryCheckmark;
return cell;
}
But checkmark is adding to the right corner of the cell I want to add it to another position inside the cell, place like below,
[[chkmrk alloc]initWithFrame:CGRectMake(200, -4, 100, 50)];
Upvotes: 0
Views: 1035
Reputation: 3990
try the following code. Actually the accessory View
is button in the cell. Make a custom cell and inside that cell position the AccessoryView
layout in the CustomCell.m
file in -layoutSubviews
Method. The code is as following:
- (void) layoutSubviews
{
[super layoutSubviews];
UIView * arrowView = nil;
for (UIView* subview in self.subviews)
{
if ([subview isKindOfClass: [UIButton class]])
{
arrowView = subview;
break;
}
}
CGRect arrowViewFrame = arrowView.frame;
arrowViewFrame = CGRectMake(200, -4, 100, 50);
arrowView.frame = arrowViewFrame;
}
This will help you sure.
Upvotes: 1
Reputation: 4272
Add a custom buttom to your cell where you want, and add an action too. If you do this you can add the button everywhere you want to be placed in the cell.
UIButton* yourCustomAccessoryButton = [[UIButton alloc]initWithFrame:CGRectMake(x, y, width, height)];
[cell addSubview:yourCustomAccessoryButton];
Upvotes: 0
Reputation: 47099
No it is not possible to change position of accessoryView
of UITableViewCell
. You need to customize your cell.
Such like add button in cell.contentView
and put image (check/uncheck image) on Button and manage (check or uncheck) it on its click event by button tag.
Upvotes: 0
Reputation: 19852
You could hack it - but safer is to just add new subview with the desired image.
[cell.contentView addSubview:yourAccesorView];
You can control position of that by setting frame.origin.x, y
Upvotes: 0