我会建议去显示交换按钮。所有的按钮将做的是交换你的来源和目的地并重新加载表格。
只是一个快速的书面记录有很多假设这里:
@interface myVC : UIViewController <UITableViewDataSource>
{
NSString* _source;
NSString* _dest;
}
@property (nonatomic, weak) IBOutlet UITableView* tableView;
@end
然后在执行:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell;
if (indexPath.row == 0)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"SourceCell"];
cell.textLabel.text = source;
}
else // indexPath.row == 1
{
cell = [tableView dequeueReusableCellWithIdentifier:@"DestCell"];
cell.textLabel.text = dest;
}
return cell;
}
- (IBAction)swap:(id)sender
{
NSString* temp = source;
source = dest;
dest = temp;
[self.tableView reloadData];
}
@end