Tôi đã tạo một ô tùy chỉnh FeatureCell có 5 hình ảnh trong hàng sẽ được gọi trong chế độ xem chính nhưng khi tôi gọi nó là hàng trống. Vì vậy, xin vui lòng nơi có thể là vấn đề của tôi?Gọi hai ô tùy chỉnh khác nhau trong một vấn đề UITableView
Tôi đã googled về ô tùy chỉnh và tôi đã sử dụng cách mà tôi phải sử dụng trong mã bên dưới nhưng không có gì xảy ra.
Đây là FeatureCell.h tôi
@interface FeatureCell : UITableViewCell{
IBOutlet UIImageView *img1;
IBOutlet UIImageView *img2;
}
@property (nonatomic, retain) UIImageView *img1;
@property (nonatomic, retain) UIImageView *img2;
@end
Đây là FeatureCell.m tôi
@implementation FeatureCell
@synthesize img,img1,img2,img3,img4;
@end
Đây là view-controller của tôi .m
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0) {
return [objectCollection count];
}
else{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier1 = @"FeatureCell";
FeatureCell *cell1 = (FeatureCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
if (cell1 == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier1 owner:nil options:nil];
cell1 = (FeatureCell*)[nib objectAtIndex:0];
}
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:CellIdentifier];
}
if ([indexPath section] == 0) {
containerObject = [objectCollection objectAtIndex:indexPath.row];
[[cell textLabel] setText:containerObject.store];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else{
cell1.img1.image = [UIImage imageNamed:@"shower.png"];
cell1.img2.image = [UIImage imageNamed:@"parking.png"];
}
return cell;
}
Bạn kết nối các cửa hàng? – Wain
Đây không phải là cách chính xác để xử lý 2 loại ô khác nhau. Xem câu trả lời của tôi ở đây: http://stackoverflow.com/questions/17711452/change-uicollectionviewcell-content-and-nib-layout-based-on-data/17711644#17711644. Điều này đề cập đến lượt xem bộ sưu tập, nhưng nó giống với chế độ xem bảng. – rdelmar
@Wain ý của bạn là gì? –