我會建議去顯示交換按鈕。所有的按鈕將做的是交換你的來源和目的地並重新加載表格。
只是一個快速的書面記錄有很多假設這裏:
@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