【发布时间】:2012-08-05 08:41:46
【问题描述】:
这是我目前制作的表格视图
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [titleArray count];
}
- (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;
}
button.tag = indexPath.row;
cell.titleLabel.text = [titleArray objectAtIndex:indexPath.row];
cell.timerLabel.text = [timeArray objectAtIndex:indexPath.row];
time = [[secondArray objectAtIndex:indexPath.row] integerValue];
NSLog(@"Title %@, time %@, second %@, time %i, tag %d", titleArray, timeArray, secondArray, time, button.tag);
return cell;
}
这是我迄今为止制作的按钮
- (IBAction)onoffBtn:(id)sender
{
NSIndexPath *indexPath = [_tableView indexPathForCell:(UITableViewCell*)[[sender superview] superview]];
NSLog(@"My tag is %d time %i, tag %d",indexPath.row, time, button.tag);
}
当我运行它时,我为每个数据放置了 3 个具有不同值的单元格,我的日志如下所示
2012-08-05 16:32:59.224 Schedule[960:f803] Title (
"Title 1",
"Test 2",
"Test 3"
), time (
"5 secs",
"10 secs",
"15 secs"
), second (
5,
10,
15
), time 15, tag 2
// after I push onoffBtn, my log is showing below
2012-08-05 16:33:01.409 Schedule[960:f803] My tag is 0 time 15, tag 2
2012-08-05 16:33:05.042 Schedule[960:f803] My tag is 1 time 15, tag 2
2012-08-05 16:33:07.113 Schedule[960:f803] My tag is 2 time 15, tag 2
对于标签,标签显示错误的时间和标签结果,即15和2。如何解决?如果您不介意,请提供代码和解释,因为我想了解。
【问题讨论】:
-
代码中的“按钮”和“时间”是什么?
-
啊,大概和这里一样:stackoverflow.com/questions/11806892/…
-
stackoverflow.com/questions/11806892/… 也是我的问题,但这次与那个问题不同。但我认为,与我的按钮或时间码无关。按钮和时间代码都只是 iboutlet 和来自我的 customcell 的输入。谢谢。