我在UITableView
中构建ViewDidLoad
,如下所示:
- (void)viewDidLoad
{
CGSize viewSize = self.view.frame.size;
mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 35, viewSize.width, viewSize.height -149)];
[mainScroll setPagingEnabled:YES];
[mainScroll setShowsHorizontalScrollIndicator:NO];
[mainScroll setDelegate:self];
[mainScroll setTag:101010];
// #1
UIScrollView *scroll1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, viewSize.height -149)];
UITableView *table101 = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, viewSize.height -149) style:UITableViewStylePlain];
[table101 setDataSource:self];
[table101 setDelegate:self];
[table101 setBackgroundColor:[UIColor clearColor]];
[table101 setTag:101];
[table101 setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[scroll1 addSubview:table101];
// #2
UIScrollView *scroll2 = [[UIScrollView alloc] initWithFrame:CGRectMake(viewSize.width, 0, viewSize.width, viewSize.height -149)];
UITableView *table102 = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, viewSize.width, viewSize.height -149) style:UITableViewStylePlain];
[table102 setDataSource:self];
[table102 setDelegate:self];
[table102 setBackgroundColor:[UIColor clearColor]];
[table102 setTag:102];
[table102 setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[scroll2 addSubview:table102];
[mainScroll addSubview:scroll1];
[mainScroll addSubview:scroll2];
[mainScroll setContentSize:CGSizeMake(viewSize.width *2, viewSize.height -149)];
}
在TableViewCell
我用过这个:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
[cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
}
NSMutableArray *mutableArray;
if (tableView.tag == 101) {
mutableArray = self.itemsInTable_Molhaq;
} else if (tableView.tag == 102) {
mutableArray = self.itemsInTable_Ziyarah;
}
NSString *labelString = [[mutableArray objectAtIndex:indexPath.row] objectForKey:@"Title"];
NSInteger indentLevel = [[[mutableArray objectAtIndex:indexPath.row] objectForKey:@"Level"] intValue];
[cell.textLabel setAttributedText:[self attributeString:labelString indentLevel:indentLevel]];
return cell;
}
一切正常,但Xcode告诉我这个:
Unsupported configuration prototype table cells must have reuse identifiers
我错过了什么?我可以得到一些帮助吗?
答案 0 :(得分:0)
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath*)indexPath
{
static NSString *cellIdentifier = @"wot";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle: someStyle reuseIdentifier: cellIdentifier];
return cell;
}
可能有帮助。
答案 1 :(得分:0)
很清楚错误说的是什么。您已在故事板中创建了原型单元格,但没有为其指定标识符。转到故事板并查看单元格的属性。填写标识符。