Я пытаюсь передать массив данных с плавающей точкой в табличное представление, но мне не удалось заставить его работать.В настоящее время я просто передаю массив с текстом для отображения, который был основан на примере.В идеале я хотел бы использовать результаты вычислений, помещаемых в массив, для заполнения табличного представления.Что бы вы предложили для выполнения этой задачи?
Кнопка
-(IBAction) selectDate:(id)sender;
{
if ( [[[sender titleLabel] text] isEqualToString:@"Set Start Date"])
{
startDate = [pickerDate date];
[startDate retain];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yy"];
labelStartDate.text = [dateFormat stringFromDate:startDate];
[dateFormat release];
//buttonDateStart.enabled = NO;
}
if ( [[[sender titleLabel] text] isEqualToString:@"Set End Date"])
{
endDate = [pickerDate date];
[endDate retain];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yy"];
labelEndDate.text = [dateFormat stringFromDate:endDate];
Используемые данные
- (void)viewDidLoad {
NSDictionary *row1 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"MacBook" , @"Name",@"White",@"Color",nil];
NSDictionary *row2 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"MacBook pro",@"Name",@"Silver",@"Color",nil];
NSDictionary *row3 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"iMac",@"Name",@"White",@"Color",nil];
NSArray *array = [[NSArray alloc] initWithObjects: row1,row2,row3, nil];
self.computers = array;
[row1 release];
[row2 release];
[row3 release];
Таблица
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return[self.computers count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellTableIdentifier = @"CellTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
if(cell == nil){
CGRect cellFrame = CGRectMake(0,0,300,65);
cell = [[[UITableViewCell alloc] initWithFrame: cellFrame
reuseIdentifier:CellTableIdentifier] autorelease];
//create the 2 rows
CGRect nameLabelRect = CGRectMake(0,5,70,15);
UILabel *nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
nameLabel.textAlignment = UITextAlignmentRight;
nameLabel.text = @"Date:";
nameLabel.font = [UIFont boldSystemFontOfSize:12];
[cell.contentView addSubview: nameLabel];
[nameLabel release];
CGRect colorLabelRect = CGRectMake(0,26,70,15);
UILabel *colorLabel = [[UILabel alloc] initWithFrame:colorLabelRect];
nameLabel.textAlignment = UITextAlignmentRight;
colorLabel.text = @"Amount:";
colorLabel.font = [UIFont boldSystemFontOfSize:12];
[cell.contentView addSubview: colorLabel];
[colorLabel release];
CGRect nameValueRect = CGRectMake(80,5,200,15);
UILabel *nameValue = [[UILabel alloc] initWithFrame:nameValueRect];
nameValue.tag = kNameValueTag;
[cell.contentView addSubview:nameValue];
[nameValue release];
CGRect colorValueRect = CGRectMake(80,25,200,15);
UILabel *colorValue = [[UILabel alloc] initWithFrame:colorValueRect];
colorValue.tag = kColorValueTag;
[cell.contentView addSubview:colorValue];
[colorValue release];
}
//Data source
NSUInteger row = [indexPath row];
NSDictionary *rowData = [self.computers objectAtIndex:row];
UILabel *name = (UILabel *)[cell.contentView viewWithTag:kNameValueTag];
name.text = [rowData objectForKey:@"Name"];
UILabel *color = (UILabel *)[cell.contentView viewWithTag:kColorValueTag];
color.text = [rowData objectForKey:@"Color"];
return cell;
}