我已將UIActivityIndicator的IBOutlet添加到自定義單元格,但它不會顯示在每個單元格上,只是在第2-3個元素上,然後不顯示任何內容。 另一件事,當我滾動表並取回過前3個單元,UIActivityIndicator從這些細胞也消失了......故事板中自定義單元格中的UIActivity指示器
代碼:
Cell.h
@interface Cell : UITableViewCell
@property (strong, nonatomic) IBOutlet UIImageView *image;
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@end
Cell.m
@implementation Cell
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
// change to our custom selected background view
}
return self;
}
@end
在故事板UIactivityIndicator設置爲: 行爲: - 動畫
用於測試目的...
和:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// load the image for this cell
Wallpaper *wallpaper = [xmlParser.wallpapers objectAtIndex:indexPath.row];
cell.label.text = wallpaper.title;
NSString *imageToLoad = wallpaper.thumbnail;
[cell.image setImageWithURL:[NSURL URLWithString:imageToLoad] placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSUInteger receivedSize, long long expectedSize)
{
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
{
//[cell.activityIndicator stopAnimating];
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(tapped:)];
[cell.image addGestureRecognizer:tap];
[cell.image setTag:indexPath.row];
CALayer * l = [cell.image layer];
[l setMasksToBounds:YES];
[l setCornerRadius:5.0];
cell.layer.cornerRadius = 7.0;
return cell;
}
您可能還想從代碼而不是從IB創建UIIndicatorView。聽起來像重複使用不正常,或者沒有在IB中分配給細胞。這裏可能會發生一些事情。 –
是的,我知道UITapGestureRecognizer,我試過設置屬性(非原子,強大)UITapGestureRecognizer * tap;到頭文件並將其加載到viewDidLoad中,它不工作;它工作正常,它不適用於每個單元格。 Rob,你有Skype嗎?我真的可以用這個幫助,我堅持了2天。 – 1337code
@MarkM,它被分配到IBOutlet,但只適用於前3個單元格,我會嘗試在代碼中創建它 – 1337code