【发布时间】:2014-10-17 16:54:03
【问题描述】:
首先,这是一个供老师考勤的应用程序,考勤将更新回我的服务器。我的 TableViewCell 自定义如下。
@interface TvcStudentClassSession : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *lblStudentInfo;
@property (strong, nonatomic) IBOutlet UISegmentedControl *smgStatus;
@property NSInteger studentId;
@end
我在 TableViewCell 中为 SegmentedControl 创建了一个 IBAction。当它被选中时,它应该调用我的网络服务并立即在服务器中更新值。这个没有问题。
现在的问题是,我的 UITableViewCell 填充在我的父视图中。代码如下。 objStudentClassSessions 是一个 NSMutableArray,用于存储从服务器加载的值。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"tvcStudentClassSession";
TvcStudentClassSession *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
ObjStudentClassSession *objStudentClassSession = [objStudentClassSessions objectAtIndex:indexPath.row];
cell.classSessionId = selectedObjClassSession.classSessionId;
cell.studentId = objStudentClassSession.studentId;
cell.lblStudentInfo.text = [NSString stringWithFormat:@"%@ (%@)", objStudentClassSession.studentName, objStudentClassSession.studentCode];
if([objStudentClassSession.attendanceStatus isEqualToString:STATUS_NONE])
{
[cell.smgStatus setSelectedSegmentIndex:0];
}
else if([objStudentClassSession.attendanceStatus isEqualToString:STATUS_PRESENT])
{
[cell.smgStatus setSelectedSegmentIndex:1];
}
else if([objStudentClassSession.attendanceStatus isEqualToString:STATUS_ABSENT])
{
[cell.smgStatus setSelectedSegmentIndex:2];
}
return cell;
}
每次用户更改 SegmentedControl 时,都会在 UiTableViewCell 类中成功调用 IBAction 并成功更新到服务器。但是一旦我向下滚动屏幕然后返回,SegmentedControl 就会恢复到原始状态,我知道这就是 iOS 的工作方式,它每次加载单元格值都变得可见。
所以对于我的情况,我可以知道如何在 UITableView 中更新我的 objStudentClassSessions 以便在单元格再次可见时正确重新加载?
【问题讨论】:
标签: ios uitableview uisegmentedcontrol