Question

I want to make marquee text in my tableViewCell. So i found some code:

- (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;
}

But when i pasted this code to my project i have error, textLabel not found. But textLabel its my text in Cell. So what i do for find TextLabel from tableViewCell in this code. Maybe you know any code for marquee in tableViewCell text or detail text. Thanks

Était-ce utile?

La solution

You can download the AutoScrollLabel files from this link http://stormyprods.com/sampleCode/AutoScrollLabel.zip

Then add these files in to your project

Import this class in your custom cell class, #import "AutoScrollLabel.h"

@interface YourCustomCell : UITableViewCell

@property(nonatomic,strong)IBOutlet AutoScrollLabel *textLabel;
@property(nonatomic,strong)IBOutlet AutoScrollLabel *detailLabel;

@end

and connect those labels outlets in YourCustomCell.xib file.

In your viewController cellForRowIndexPath method,

-(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;

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top