0
我試圖將值傳遞給表格單元格,但是當我用userdata.title 替換字符串時,它顯示爲空白。 userdata是另一個類UserData的對象,它是外部的,我將它導入。 UserData從所有視圖訪問,以將對象從一個控制器傳遞到另一個控制器。現在,如何將值傳遞給表格,並且如果我決定通過文本字段添加更多值,我該如何保留它?將數據傳遞到表單元格
- (void)viewDidLoad
{
tabledata = [[NSMutableArray alloc] initWithObjects:@"hello", nil];
tablesubtitles = [[NSMutableArray alloc] initWithObjects:@"hello", nil];
[super viewDidLoad];
//if I use "userdata.title" in replacemnent of @"hello" above, the table show up blank
//self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
//--------------------------------------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return [tabledata count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"homeworkcell"];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"homeworkcell"];
}
cell.textLabel.text = [tabledata objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [tablesubtitles objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:14.0];
//static NSString *CellIdentifier = @"Cell";
/* if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}*/
// Configure the cell.
//-----------------------------------------START----------------------------Set image of cell----
cellImage = [UIImage imageNamed:@"checkboxblank.png"];
cell.imageView.image = cellImage;
//--------------------------------------------END---------------------------end set image of cell--
return cell;
}
如何將userData傳遞給此類? – beryllium 2012-02-21 21:42:55
#導入「UserData.h」,然後UserData * userdata; – user1191343 2012-02-21 21:44:01
這不是一個傳球,它只是一個頭部導入。在哪裏創建它,初始化和設置爲表的數據源? – beryllium 2012-02-21 21:45:30