سؤال

I want to add an UIActivityIndicator to an UITableViewCell. How can I do?

هل كانت مفيدة؟

المحلول

try like this

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"NoReuse"] autorelease];
cell.textLabel.text = @"Loading...";

UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] 
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];

// Spacer is a 1x1 transparent png
UIImage *spacer = [UIImage imageNamed:@"spacer"];

UIGraphicsBeginImageContext(spinner.frame.size);

[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)];
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
cell.imageView.image = resizedSpacer;
[cell.imageView addSubview:spinner];
[spinner startAnimating];

return cell;

نصائح أخرى

UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
spinner.frame = CGRectMake(205.0f, 0.0f, 44.0f, 44.0f);
spinner.tag = 3;
[cell.contentView addSubview:spinner];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top