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