我想动态修改单元格的内容,即使在重新加载数据后我也无法正常工作。正如预期的那样,当视图加载时,我在桌子上垂直得到 1 1 1 1 1 1 1,当我按下段 1 时,我得到 4 4 4 4 4 4 4 正如预期的那样,但是,当我按下 2 时,我得到 -1 - 1 -1 -1 -1 -1 再次,当我按 3 时,我再次得到 4 4 4 4 4 4 4。此外,我的单元格的内容取决于我按下按钮的顺序。我的代码在下面的表格中只有一行和许多部分:
- (void)viewDidLoad
{
currentarray=[NSArray arrayWithObjects:@"-1",@"-2",@"-3", @"-4", nil];
}
- (IBAction)SegControl: (id) sender{
for(int i=0; i<4; i++){
if(theSegControl.selectedSegmentIndex==i){
buttonpressed[i]=[NSNumber numberWithInt:1];
}
else {
buttonpressed[i]=[NSNumber numberWithInt:0];
}
}
if([buttonpressed[0] intValue]==1){
currentarray=sorteddectotalteamPoints;
}
else if([buttonpressed[1] intValue]==1){
currentarray=[NSArray arrayWithObjects:@"4",@"6",@"7", @"8", nil]; NSLog(@"%@",@"two pressed");
}
else if([buttonpressed[2] intValue]==1){
currentarray=[NSArray arrayWithObjects:@"9",@"10",@"11", @"12", nil]; NSLog(@"%@",@"three pressed");
}
else {
currentarray=[NSArray arrayWithObjects:@"13",@"14",@"15", @"16", nil]; NSLog(@"%@",@"four pressed");
}
//to update the cells
for(int i=0; i<[teamnameswithoutRepeat count];i++){
[byTeam reloadSections:[NSIndexSet indexSetWithIndex:i] withRowAnimation:UITableViewRowAnimationFade];
}
NSLog(@"%@",currentarray);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, tableView.rowHeight)] ;
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
label.layer.borderColor = [UIColor whiteColor].CGColor;
label.layer.borderWidth = 1.0;
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.section];
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[MyTableCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] ;
if(tableView==byTeam)
{
//[tableView reloadData];
label.text=[currentarray objectAtIndex:0];
[cell.contentView addSubview:label];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
// UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
//cell.textLabel.text = @"updated text";
}
}
}