首先关闭标签不会工作.我这样说是因为我创建了4个按钮,它们都具有特定单元格的相同标签,即indexPath.row = tag.
在我的TableViewCellForRowAtIndexpath中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"courseCell";
//Step 1: Check to se if we can reuse a cell from a row that has just rolled off the screen
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//step 2: If there are no cell to reuse, create a new one
if (cell == nil){
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
...
//-------------Creation of Custom Buttons-------------//
//-----img = "radioOn.png"-----//
//----img2 = "radioOff.png"----//
//----RadioButtonA----// …Run Code Online (Sandbox Code Playgroud) 我有一个UIStepper控件,我在我的程序中创建UITableViewCell.我还UILabel为该单元创建了一个程序化的程序.发生的事情是,按下时的步进器访问UILabel位于不同单元格中的位置,即索引路径1而不是0.这里是代码.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
//---------UIStepper Creation-------------------//
stepper = [[UIStepper alloc]init];
[stepper setFrame:CGRectMake(220.0f, 65.0f, 0.0f, 0.0f)];
[stepper setTag: indexPath.row];
[stepper addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChanged];
stepperLabel = [[UILabel alloc] init];
[stepperLabel setFrame:CGRectMake(105,70, 20, 20)];
[stepperLabel setTextColor:[UIColor whiteColor]];
[stepperLabel setBackgroundColor:[UIColor clearColor]];
[stepperLabel setTag:stepper.tag];
[stepperLabel setText:[NSString stringWithFormat: @"%d", (int) [stepper value]]];
stepperLabel.lineBreakMode = UILineBreakModeWordWrap;
stepperLabel.numberOfLines = 1;//Dynamic
//Set min and max
[stepper setMinimumValue:0];
[stepper setMaximumValue:4];
// Value wraps around from minimum to maximum …Run Code Online (Sandbox Code Playgroud)