【发布时间】:2013-02-22 07:03:21
【问题描述】:
我有表格视图,在第二部分的行中我放置了一个按钮,当我滚动表格视图时,此按钮也会出现在其他行中。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kCellID = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];/////self...ramesh
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellID];
}
if (indexPath.row==1)
{
cell.accessoryView=[[UIView alloc]initWithFrame:self.warmUpSwitch.frame];
cell.textLabel.text=@"Warm Up(5 min.)";
[cell.accessoryView addSubview:self.warmUpSwitch];
}
if (indexPath.row==2)
{
cell.accessoryView=[[UIView alloc]initWithFrame:self.coolDownSwitch.frame];
cell.textLabel.text=@"Cool Down(5 min.)";
[cell.accessoryView addSubview:self.coolDownSwitch];
}
}
【问题讨论】:
-
你能展示你的代码吗,我怀疑你对所有单元格都使用了可重用性,并为不需要的单元格获取按钮
-
虽然这不是一个好方法,但将可重用标识符设置为 nil 会对您有所帮助。
-
请发布您的代码如何添加按钮
-
我已经添加了代码,请检查一下。
-
你能发布整个方法如何初始化单元格吗?
标签: iphone object user-interface location