这是我到目前为止制作的表格视图
- (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。如何解决?如果您不介意,请提供代码和解释,因为我想了解。