English 中文(简体)
事实 单位:荷兰
原标题:UItableViewCell acting as a button
  • 时间:2010-11-27 11:11:41
  •  标签:
  • iphone
  • cocoa

I cannot get the right way to do the following stuff... (I m sure I m not that far but...) I have a UITableView and within this table I want a particuliar cell to be displayed as a button. At first I tried to add a button in the cell but I read that was not the right way to do it. Instead it seems better to customize the cell (and make it look like a button). The thing is, I do not really know what subview to change... What I need: - no arrow beeing displayed at the right of the cell (I though UITableViewCellAccessoryNone would do the trick... but it did not...). - the cell to be blue (same blue as the one used when it s clicked)

The following is the code I use:

NSString *section = (NSString *)[sections objectAtIndex:indexPath.section];
NSNumber *row = indexPath.row;
NSString *cellValue = (NSString *)[(NSArray *)[items objectForKey:section] objectAtIndex:row]; 
cell.textLabel.text = cellValue;

// Make Cell look like a button (used for disconnect option)
if([[sections objectAtIndex:indexPath.section] isEqualToString:@"connection"]) {
    cell.textLabel.text = @"Disconnect";
    cell.textLabel.textAlignment = UITextAlignmentCenter;

    for (UIView* view in cell.contentView.subviews)
    {
        view.backgroundColor = [UIColor clearColor];
        }
    cell.accessoryType= UITableViewCellAccessoryNone;
}

感谢您的帮助,

页: 1

问题回答

First of all delete the code for cell Accessory view.. and to make it looks like a button, there are several possible solutions . you can make a background image for the cell like button . if you are facing a problem of accessory view that its not hiding , make an image like a button , and set the background image property of cell .

[Cell setBackground 图像:[UIImagetusNamed:“Yourfilename.png”]

比如,如果这样做不奏效,并试图在子调查中增加形象。

[Cell AddSubview: [[UIImageView alloc] initWithImage:[UIImage cultureNamed:@ “imagename.png]]]

这可能有助于!

Thanks Yasir





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签