这是我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];}
self.credits = (UILabel*)[cell viewWithTag:101];
self.credits.text = @"Available Credits";
cell.backgroundColor = [UIColor redColor];
self.credits.textColor = [UIColor blackColor];
[cell.contentView addSubview:self.credits];
信用是这里的标签
答案 0 :(得分:0)
您在UIViewController
中存储了一个小区标签,然后在内容视图中尝试addSubview
。
正确的做法应该是:
UITableViewCell
cellForRowAtIndexPath:
中使用该属性名称指定Available Credits
你的cellForRowAtIndexPath
最终应该是这样的:
- (MyCustomUITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
self.myNewProperty.text = @"Available Credits";
}