标签: reuseidentifier

更新MKAnnotationview的UILabel-Subview

我有一个MapView集群注释(ADMapCluster).I want to show the amount of elements in the Cluster因此我将一个UILabel添加到MKAnnotationView作为子视图.

我的问题是,当我在缩放或类似操作后重用MKAnnotationView时,UILabel不会更新文本.

- (MKAnnotationView *)mapView:(ADClusterMapView *)mapView viewForClusterAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

MKAnnotationView * pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ADMapCluster"];
if (!pinView) {
    pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ADMapCluster"];
    pinView.image = [UIImage imageNamed:@"map-markers"];
    UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 5, 25, 20)];
    countLabel.textAlignment = NSTextAlignmentCenter;
    [countLabel setTag:2];
    countLabel.text = [NSString stringWithFormat:@"%d",[[(ADClusterAnnotation*)pinView.annotation originalAnnotations] count] ];
    countLabel.font = [UIFont fontWithName:@"Avenir-Book" size:10];
    [pinView addSubview:countLabel];

}
else …
Run Code Online (Sandbox Code Playgroud)

mapkit mkannotation reuseidentifier mkannotationview ios

5
推荐指数
0
解决办法
798
查看次数

iOS - UITableView不显示单元格

我在storyboard中设置了以下界面:

在此输入图像描述

控制器是一个从UITableViewController扩展的自定义控制器.当我运行我的应用程序时,这就是我得到的:

在此输入图像描述

我认为它可能与重用标识符有关,所以我将它们更改为每个单元格的唯一内容,并相应地修改了代码,但仍然没有显示任何内容.

uitableview reuseidentifier ios

4
推荐指数
1
解决办法
7280
查看次数

从可重用的Cell中出列时,自定义CollectionViewCell会触发什么方法?

ItemCollectionViewCell通常使用其父ViewController中的方法将可重用的自定义出列

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ItemCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
}
Run Code Online (Sandbox Code Playgroud)

但是ItemCollectionViewCell我已经实现了initWithFrame最初只调用的方法,但是当一个单元格被重新使用时没有被调用.

ItemCollectionView在调用[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]父视图控制器之后,在重新添加到队列之前触发内部的方法是什么?

reuseidentifier ios uicollectionviewcell

4
推荐指数
1
解决办法
1040
查看次数

更改一个可重用单元格的UITableViewController会影响其他单元格

我有一个非常简单的UITableViewController子类,旨在向用户显示单元格中字母表中的字符.当用户按下单元格时,将其附件类型设置为选中标记.

#import "MTGTableViewController.h"

@interface MTGTableViewController ()

@property (nonatomic, strong) NSArray *data;

@end

@implementation MTGTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    _data = @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _data.count;
}


- (UITableViewCell …
Run Code Online (Sandbox Code Playgroud)

uitableview didselectrowatindexpath reuseidentifier ios

4
推荐指数
2
解决办法
2340
查看次数

滚动时表格视图单元消失

这个问题不一定会出现

有时滑动时消失有时不消失

更多信息请点击此处

点击显示 gif

点击显示故事板 png

代码

HSubjectCell *cell = [tableView dequeueReusableCellWithIdentifier:kSubjectCellIdentifier forIndexPath:indexPath];
_subjectView = cell;
cell.delegate = self;
cell.subject = self.subjectArr[indexPath.section - 3];
return cell;
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview tablecellrenderer reuseidentifier ios

4
推荐指数
1
解决办法
4614
查看次数

iOS Swift UICollectionView registerNib 用于可重用视图不起作用

我正在尝试使用 UICollectionViewController 创建一个类似的 iCalendar。现在我正在尝试添加可重用视图作为每天的列标题。

我制作了一个故事板并添加了一个链接到此类的 UICollectionViewController:

import UIKit

class WeekViewController: UICollectionViewController, UICollectionViewDelegate
{
    let dataSource = WeekViewDataSource()
    let weekLayout = WeekViewLayout()

    override func awakeFromNib() {
        var columnHeaderViewNIB = UINib(nibName: "ColumnHeaderView", bundle: nil)
        self.collectionView?.registerNib(columnHeaderViewNIB, forSupplementaryViewOfKind: columnHeaderViewIdentifier, withReuseIdentifier: columnHeaderViewIdentifier)

        self.collectionView?.collectionViewLayout = weekLayout
        self.collectionView?.dataSource = dataSource

        super.awakeFromNib()
    }
}
Run Code Online (Sandbox Code Playgroud)

ColumnHeaderView nib 实际上是一个 xib 文件,其视图包含单个标签。该视图链接到此类:

import UIKit

class ColumnHeaderView: UICollectionReusableView
{
    @IBOutlet weak var label: UILabel!
}
Run Code Online (Sandbox Code Playgroud)

数据源和布局:

import UIKit

class WeekViewDataSource: NSObject, UICollectionViewDataSource {

    var events = Array<String>()

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: …
Run Code Online (Sandbox Code Playgroud)

nib collectionview reuseidentifier ios swift

2
推荐指数
1
解决办法
6476
查看次数

不使用 UITableView 中的可重用单元格和每个单元格中的 CollectionView

我有一个UITableView并且在它的原型单元中有一个UICollectionView.

MainViewController是代表,UITableViewMyTableViewCell班级是代表UICollectionView

在更新每个TableViewCell内容时,我调用cell.reloadData()使单元格内的 collectionView 重新加载其内容。

当我使用可重用单元格时,当每个单元格出现时,最后一个单元格的内容消失了!。然后它从 URL 加载正确的内容。

UITableViewCells最多有 5 到 10 个。所以我决定不将可重复使用的单元用于UITableView. 我将 tableView 方法中的单元格创建行更改为:

let cell = MyTableViewCell(style: .default, reuseIdentifier:nil)
Run Code Online (Sandbox Code Playgroud)

然后我在 MyTableViewCell 类(它是 UICollectionView 的委托)中得到一个错误,在这个函数中:

override func layoutSubviews() {
    myCollectionView.dataSource = self
}

EXC_BAD_INSTRUCTION CODE(code=EXC_I386_INVOP, subcode=0x0)
fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)

MyTableViewCell.swift

import UIKit
import Kingfisher
import Alamofire

class MyTableViewCell: UITableViewCell, UICollectionViewDataSource {


    struct …
Run Code Online (Sandbox Code Playgroud)

uitableview reuseidentifier ios uicollectionview swift

2
推荐指数
1
解决办法
2259
查看次数

iOS:未使用reuseidentifier清除单元格内容

我正在尝试使用在UILabels中列出数组的单元格构建一个表.因此,每个单元格的大小和标签数量都由该数组中的对象数量决定.但是,我遇到了一个问题,其中内容最初是正确输入的,但随后在滚动期间表单元格被回收,内容无法清除.

UITableView损坏的重叠单元格内容

这是我的整个实现.如果有人可以请我解释一下如何防止在回收过程中保留标签,我真的很感激.谢谢.

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
    UITableView *tableView;
}

@end
Run Code Online (Sandbox Code Playgroud)

ViewController.m

#import "ViewController.h"
#import "CustomCell.h"

@interface ViewController () {
    NSArray *myTableArray;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Set up View
    self.view = [[UIView alloc] initWithFrame: [UIScreen mainScreen].applicationFrame];
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.clipsToBounds = YES;
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    // Set up Table
    CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
    tableView.backgroundColor = [UIColor clearColor]; …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview reuseidentifier ios

1
推荐指数
1
解决办法
4613
查看次数

注册的NIB,当我使用dequeueReusableCellWithIdentifier时仍然会出现断言错误

我有一个自定义UITableViewCell类,我想用它来创建自定义表格单元格.我创建了自定义表格单元格的xib及其标题和实现文件,全部调用RTRepairOrderTableCell.m/.h/.xib.

我的问题是,即使我将表格单元格的重用标识符设置为RTRepairOrderTableCell.xib文件内部并在我的表视图控制器中注册了xib,我仍然在尝试出列或创建新单元格时出现断言错误使用.

在我的视图(表)控制器内部,我有以下内容:

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Load the nib file
    UINib *nib = [UINib nibWithNibName:@"RTRepairOrderTableCell"
                                bundle:nil];
    // Register this Nib, which contains the cell
    [self.tableView registerNib:nib
         forCellReuseIdentifier:@"RTRepairOrderTableCell"];    
}
Run Code Online (Sandbox Code Playgroud)

这里没有错误,它完成viewDidLoad得很好.

在我的内心cellForRowAtIndexPath我有以下内容:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{       
    RTRepairOrderTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RTRepairOrderTableCell" forIndexPath:indexPath];      
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

根据我见过的每个教程,只要我在xib文件中正确设置了重用标识符并且我viewDidLoad在视图控制器类中注册了将显示表格单元格的xib,这应该可以工作,所以我在失去了我为什么得到

*** Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:], /SourceCache/UIKit/UIKit-2935.138/UITableView.m:5413
Run Code Online (Sandbox Code Playgroud)

xcode objective-c xib reuseidentifier

1
推荐指数
1
解决办法
2269
查看次数