到点,我有自定义单元格,里面有2个标签和1个文本框。标签和文本字段都有来自用户的输入。我也有其他观点,它里面有可用的视图。我的问题是我如何在uitableview中填充单元格?请帮忙。如何使用单元填充tableview?
这是我在tableviewcontroller里面的代码。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1; // i want to populate this using 'count' but i dont know how.
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:[CustomCell reuseIdentifier]];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = _customCell;
_customCell = nil;
}
cell.titleLabel.text = [NSString stringWithFormat:@"%@",titleTextString];
cell.timerLabel.text = [NSString stringWithFormat:@"%@",timerString];
cell.statusLabel.text = [NSString stringWithFormat:@"%@",statusString];
return cell;
}
如何在用户输入完成后按下添加按钮来填充我的tableview?请如果你不介意帮助我的代码。我是初学者,很难用意见来理解。
谢谢你的回答,但是我应该在numberOfRowsInSection里写什么?我的意思是,我如何填充我的单元格在tableview中,如果我按“添加”按钮。 – SyntaxError 2012-07-29 10:33:39
通常情况下,您将拥有一个'NSMutableArray',您将在其中推送所有新数据,因此每次单击添加按钮时,都会在该数组中添加新数据。因此,你可以在'numberOfRowsInSection'中使用数组的大小,这种情况下''yourArray count];'还请记住,如果你的行数据是混合的东西,你可以使用'NSMutableDictionary'来代替。 – antf 2012-07-29 10:42:37
呃...即时通讯抱歉,我应该写在cellForRowAtIndexPath内?我把我的数组放在numberOfRowsInSection中,使用return [array count];但是我应该在cellForRowAtIndexPath里面添加什么?谢谢。 – SyntaxError 2012-07-29 11:41:34