开发者

toggle checkbox image in uitableviewcell

开发者 https://www.devze.com 2023-02-22 11:20 出处:网络
I\'ve been having a problem of adding a checkbox image to my uitableviewcell and toggle between checked and unchecked image.

I've been having a problem of adding a checkbox image to my uitableviewcell and toggle between checked and unchecked image.

My simple code is:

-(UITableViewCell *)tableView:(UITableView *)todoTable cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.todoTable dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

if (!cell)开发者_JAVA技巧 { 
    cell = [[[UITableViewCell alloc]
             initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}

cell.textLabel.text = [self.todoList objectAtIndex:indexPath.row]; 

return cell;
}

and i try to add in the solution in from here

But i don't know where shall i put the interface ToggleImageControl : UIControl I assume i put it in the same header file as my viewcontroller?

also i try to put in

ToggleImageControl *toggleControl = [[ToggleImageControl alloc] initWithFrame: <frame>];
toggleControl.tag = indexPath.row;  // for reference in notifications.
[cell.contentView addSubview: toggleControl];

into my code above, i will get a ToggleImageControl reference error because of the implementation of the interface is not found, how can i fix this?

Thanks.


The easiest way to accomplish such modifications in look and behaviour is to write your own subclass of UITableViewCell. UIButton actually has toggling feature built in via selected property.


KakoSquid is correct. It looks like you might need to spend some time getting to know how classes and subclasses are built.

In your case it sounds like you have made a new interface section for your ToggleImageControl in the .h file but you need to put an @implementation section in your .m file.

In many situations you will make a new file set for a new class. (.h & .m files). In this case a toggle image is something you could reuse across other projects so it would make sense to break it out into its own file.

But, you can add the interface and implementation into any existing flies as you see fit. Just make sure to #import the correct files where you are using them.

0

精彩评论

暂无评论...
验证码 换一张
取 消