我想在tableViewCell中制作字幕文本。所以我找到了一些代码:
- (void)fireTimer
{
NSMutableString *mutableText = [NSMutableString stringWithString: textLabel.text];
//Takes the first character and saves it into a string
NSString *firstCharText = [mutableText substringWithRange: NSMakeRange(0, 1)];
//Removes the first character
[mutableText deleteCharactersInRange: NSMakeRange(0, 1)];
//Adds the first character string to the initial string
[mutableText appendString: firstCharText];
textLabel.text = mutableText;
}
但是当我将此代码粘贴到我的项目时,我有错误,找不到textLabel。但是textLabel是我在Cell中的文字。所以我在这段代码中从tableViewCell中找到TextLabel。也许你知道tableViewCell文本或详细文本中的marquee的任何代码。感谢
答案 0 :(得分:2)
您可以从此链接http://stormyprods.com/sampleCode/AutoScrollLabel.zip
下载AutoScrollLabel文件然后将这些文件添加到您的项目中
在自定义单元格类#import "AutoScrollLabel.h"
@interface YourCustomCell : UITableViewCell
@property(nonatomic,strong)IBOutlet AutoScrollLabel *textLabel;
@property(nonatomic,strong)IBOutlet AutoScrollLabel *detailLabel;
@end
并在YourCustomCell.xib
文件中连接这些标签插座。
在viewController cellForRowIndexPath方法中,
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
YourCustomCell *cell= (answerCustomCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"YourCustomCell" owner:self options:nil];
for(id currrentObject in topLevelObjects)
{
if([currrentObject isKindOfClass:[UITableViewCell class]])
{
cell = (YourCustomCell*)currrentObject;
break;
}
}
}
cell.textLabel.text = @"Your text";
cell.detailLabel.text = @"Your text";
return cell;
}