制作第一行tableView Empty iphone

时间:2011-10-14 14:02:10

标签: iphone

在我的应用程序中,我有一个tableView。我想在表视图的第一行显示明天日期(下一个日期),其余行显示其他数据。如何让第一行为空,然后在其中显示日期。

我的代码是

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}





    NSUInteger row=[indexPath row ];

if (row==0) {
    cell.textLabel.text=@"hi";
}

else{



cell.textLabel.text = [dataFromXml objectAtIndex:indexPath.row];


// cell.detailTextLabel.text = [data objectAtIndex:row];

NSString * detail = [dataFromXml2 objectAtIndex:row];     NSString * dist = [距离objectAtIndex:row];

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setPositiveFormat:@"##0.## km"];
[numberFormatter setNegativeFormat:@"##0.## km"];
NSNumber *number = [NSNumber numberWithDouble:[dist doubleValue]];
NSString *formattedString = [numberFormatter stringFromNumber:number];




NSString *detailSting=[NSString stringWithFormat:@"%@"" - ""%@",detail,formattedString];
cell.detailTextLabel.text = detailSting;

[numberFormatter release];

cell.textLabel.font=[UIFont boldSystemFontOfSize:15];
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
self.rowImage=[UIImage imageNamed:@"redicon.png"];

cell.imageView.image= self.rowImage;


return cell;

}

}

1 个答案:

答案 0 :(得分:3)

只需在你的cellForRowAtIndexPath中创建一个特例:

if (indexPath.row == 0) {
    /* handle special cell */
}
else {
    /* do your usual stuff */
}

要明天的约会,你可以这样做:

NSDate *today = [NSDate date];
NSDate *tomorrow = [today dateByAddingTimeInterval:60*60*24];

然后使用NSDateFormatter转换为字符串。