iOS在动态表的顶部创建一个静态单元格
标题差不多就是这么说的。如何在动态表的顶部创建一个静态单元格?我希望能够使用它作为我的表的图例。谢谢 以下是我的tableView代码:iOS在动态表的顶部创建一个静态单元格,ios,xcode,uitableview,dynamic,Ios,Xcode,Uitableview,Dynamic,标题差不多就是这么说的。如何在动态表的顶部创建一个静态单元格?我希望能够使用它作为我的表的图例。谢谢 以下是我的tableView代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; JointCAD *currentCall = [[xmlPar
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"texture3.png"]];
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UIView *selectionView = [[UIView alloc] initWithFrame:CGRectMake(10, 7, 200, 65)];
[selectionView setBackgroundColor: [UIColor clearColor]];
cell.selectedBackgroundView = selectionView;
}
cell.callTypeLabel.text = currentCall.currentCallType;
cell.locationLabel.text = currentCall.location;
cell.unitsLabel.text = currentCall.units;
cell.stationLabel.text = [@"Station: " stringByAppendingString:currentCall.station];
if ([currentCall.callType isEqualToString:@"F"]) {
cell.imageType = Fire;
}
else {
cell.imageType = EMS;
}
if ([currentCall.county isEqualToString:@"W"]) {
cell.imageType1 = Washington;
}
else {
cell.imageType1 = Clackamas;
}
return cell;
}
这似乎更像是希望表有一个标题,而不是一个静态单元格。如果我理解您的问题,您需要一个位于顶部且不移动的单元格,而动态部分中的其他单元格按正常方式上下滚动 如果是这种情况,请使用返回标题视图及其大小的tableviewdelegate方法
如果不是这样,那么我不理解你的问题,对不起。我也有类似的问题。我希望在顶部有一部分动态单元格,在底部有一些其他部分都是静态的。我使用了一种变通方法,其中我只需操纵实际出现在顶部的单元格数量,即使整个tableView只是一个静态tableView。我知道我只会在表格的动态部分使用最多7个单元格,所以只要你确保在动态部分一次出现的最大单元格数是,我考虑过了。我希望它能够与表格一起滚动,这就是为什么页眉基本上不起作用的原因,我所需要的只是添加一个静态单元格作为表格中的第一个单元格,这样它就一直保持在那里。啊,我明白了。好的,我会让numberofrows总是将1添加到您的计数中,如果indexpath.row==0,那么就为静态单元格进行配置。是的,这就是我最后要做的!谢谢。是的,这将非常有效,除了我的单元格由一个xml解析器填充,它可以有1个单元格到25个以上的单元格,没有办法知道。但不管怎样,我用上面的答案算出了。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int i;
switch(section) {
case 0:
//Do a bunch of checking here on how many i actually need. Then, I will just return the required amount.
// As long as it is less than the number of cells I have statically placed in my .xib, everything works good.
return i;
case 1:
return 3;
case 2:
return 1;
case 3:
return 2;
default:
return 0;
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell*)currentCell forRowAtIndexPath:(NSIndexPath*)indexPath
{
// DB_NSLog((@"will display CELL"));
if(indexPath.section==0){
currentCell.textLabel.text=nil;
for(int i=0;i<numberOfDevices;i++)
{
//get the names of connected devices from whatever they're array they are stored in
//assign to respective labels
//just using row indexes as tester for passing to the device specifiic settings page
if(i==indexPath.row){
//do whatever customization you want here
currentCell.textLabel.text=[tempDic objectForKey:@"deviceName"];
// currentCell.textLabel.textAlignment=UITextAlignmentCenter;
currentCell.textLabel.font=[UIFont fontWithName:@"System" size:17];
currentCell.textLabel.textColor=[UIColor colorWithRed:0 green:0.32156863 blue:0.54117647 alpha:1.0];
}
}
}