我有一个静态的UITableView
,我通过cellForRowAtIndexPath
方法将其填充到NSDictionary中。以静态方式在UITableViewCell中以编程方式添加控件UITableView
NSString *key = [sectionKeys objectAtIndex:[indexPath section]];
NSArray *contents = [sectionContents objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[[cell textLabel] setText:contentForThisRow];
认为运行良好,我还需要添加控件到tableviewcells和每个单元格有不同的控制。当我以编程方式将UITextField添加到cell1时,运行后的视图直到5个部分都很好,但是当我向下滚动我的tableview时,第6部分的单元格也会获得UITextField控件。 UIDatePicker也一样,我的tableview的前5个部分都很好,但在滚动tableview时,最后两部分也获得了UIDatePicker控件。
注:我有9个表格视图中的每个部分都有一个单元格,但前两个部分包含两个单元格。
我正在动态创建单元格,然后如何为它们分配标识符,分配标识符和创建控件都发生在cellForRowAtIndexPath中? – Firdous 2012-03-14 07:56:36
是的,只需将'CellIdentifier'的值改为任何你需要的 – Novarg 2012-03-14 07:58:02
像猎豹一样工作:)谢谢 – Firdous 2012-03-14 08:04:34