【发布时间】:2014-07-17 09:00:56
【问题描述】:
我正在尝试在我的表格视图中的某些单元格上显示一个按钮,具体取决于该单元格中显示的图像类型
我有两个 NSMutableArray,一个保存缩略图 URL,另一个 NSMutableArray 保存 URL 的类型(如果它是图像或视频)
问题是按钮未显示在所有视频类型单元格上
这是我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TVCustomCell";
TVCustom *cell = (TVCustom *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TVCustom" owner:self options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[TVCustom class]]) {
cell = (TVCustom *) currentObject;
break;
}
}
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *imgURL = [arrayImagesURL objectAtIndex:indexPath.row];
NSURL *imageURL = [NSURL URLWithString:imgURL];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageWithData:imageData];
cell.thumbImg.image = image;
});
});
NSString *MediaType = [NSString stringWithFormat:@"%@", [arrayType objectAtIndex:indexPath.row]];
if ([MediaType isEqualToString:@"video"]) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(120, 319, 50, 30);
[button setTitle:@"Play" forState:UIControlStateNormal];
button.tag = indexPath.row;
[button addTarget:self action:@selector(PlayBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor= [UIColor clearColor];
[cell.contentView addSubview:button];
}
return cell;
}
我不知道我做错了什么,知道吗?
【问题讨论】:
-
一次检查 button.frame = CGRectMake(120, 319, 50, 30);这个按钮的框架 y 坐标从 319 开始检查它。
-
@Sunny 是的,我的自定义单元格高度是 350,我的按钮在单元格的底部,它不在单元格框架之外
-
为什么每次都分配按钮,即使你有自己的自定义单元格
TVCustom。在 TVCustom 上添加按钮并根据 MediaType 隐藏或显示。 -
一旦检查断点天气是否被执行?
-
@trick14 已经这样做了,但遇到了同样的问题
标签: ios objective-c xcode uitableview